Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder student's Avatar
    Join Date
    Jan 2007
    Posts
    129
    Thanks
    13
    Thanked 0 Times in 0 Posts

    how to rename images and save them to different folder using PHP?

    helllo,
    ( since this is an entirely different question i am posting it as a new message.)

    for example,
    i have an image here: htp://domain.com/images1/image.jpg
    i would like to rename this image as renamedimage.jpg
    and move it to another folder htp://domain.com/images2/renamedimage.jpg

    how can this be done using PHP?

    ( i have thousands of images. so i am thinking of using some php script to do this task )
    please reply with possible solutions.
    thank you very much

  • #2
    New Coder
    Join Date
    Jul 2005
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could use php copy(source, destination) function
    If you can not find a decision, maybe you have to try to change a problem

    http://www.gunman.co.nr
    http://bglinux.org

  • #3
    Regular Coder student's Avatar
    Join Date
    Jan 2007
    Posts
    129
    Thanks
    13
    Thanked 0 Times in 0 Posts
    hello gunman,
    thanks for the tip.
    but i have a problem.
    i used the code as follows:
    i kept it in a while loop because there are thousands of images to rename

    $file = 'htp://domain.com/images/image1.jpg';
    $newfile = 'htp://domain.com/renamedimages/renamedimage1.jpg';

    copy($file, $newfile);


    and the result is all the images are the same. ( image1 is copied into image2, image3, image4 and all )
    i think i have to use imagedestroy function. but dont know how to use the function in this context.
    i have tried several ways and the result is:
    imagedestroy(): supplied argument is not a valid Image resource.

    i could copy individual files very well using this function.
    please inform me how to copy the images recursively.
    thank you very much for any help

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,074
    Thanks
    2
    Thanked 320 Times in 312 Posts
    If the same source file given by the $file variable got copied into each destination $newfile, that would indicate that the $file variable did not get modified within your while loop for each file.

    imagedestroy() is an GD image manipulation function and not a file handling function - http://www.php.net/manual/en/ref.filesystem.php If you want to delete a file after it has been successfully copied, use the unlink() function - http://www.php.net/unlink
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •