fopen problem

Discussion in 'PHP' started by mirosoft1, Sep 14, 2010.

  1. #1
    Dear all
    i have a file called image.jpg and i use a code to open the image and write on it
    then close the file
    i want to rename this image and move it to another folder

    this is the code
    
    Imagejpeg($im,'',100);
         $Image= ob_get_contents();
         ob_end_clean();
         $fp = fopen ("image.jpg", "w");
         fwrite ($fp, $Image);
         fclose ($fp);
    
    
    PHP:

    i wanna to rename the file image.jpg and move it to another folder
    please help urgent
    thanks
     
    mirosoft1, Sep 14, 2010 IP
  2. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #2
    Thorlax402, Sep 14, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    Also can use file_get_contents() and file_put_contents()
     
    danx10, Sep 14, 2010 IP
  4. mirosoft1

    mirosoft1 Well-Known Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #4
    thank you for all answers but you speak about how to move the file
    no one tell me how to rename the file image.jpg????
    thanks
     
    mirosoft1, Sep 15, 2010 IP
  5. Mohie

    Mohie Peon

    Messages:
    122
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    try:
    <?php
    rename("image.jpg", "newimagename.jpg");
    ?>

    make sure this php file exist in the same folder of ur image , otherwise u need to specify the path.

    regards,
    Mohie.
    ---------------------------------------------------------------------
    If you like my post, please add some reputation.
     
    Mohie, Sep 15, 2010 IP
  6. mirosoft1

    mirosoft1 Well-Known Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #6
    ok i will try it
    thanks mazako,mohie,Thorlax402 and danx10
     
    mirosoft1, Sep 16, 2010 IP
  7. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #7
    When you are using the move functions provided, you also provide a new name for the file so it is basically like renaming it except you can put it in other directories.
     
    Thorlax402, Sep 16, 2010 IP