SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Jul 2004
    Location
    USA
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Raname Uploaded Image

    Hello,

    I have an upload form to upload images to my website. It currently resizes the image, but how could I alter this to be able to change the name of the file itself?

    PHP Code:
    $uploadedfile $_FILES['uploadfile']['tmp_name'];

    $src imagecreatefromjpeg($uploadedfile);

    list(
    $width,$height)=getimagesize($uploadedfile);

    $newwidth=600;
    $newheight=($height/$width)*600;
    $tmp=imagecreatetruecolor($newwidth,$newheight);

    imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

    $filename "images/"$_FILES['uploadfile']['name'];

    imagejpeg($tmp,$filename,100);

    imagedestroy($src);
    imagedestroy($tmp); 
    Thanks
    BKerr

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,435
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    This is your filename:
    PHP Code:
    $filename "images/"$_FILES['uploadfile']['name']; 
    In this case its putting the new images in the images folder and calling it by the original filename.
    Alter the path etc. to what you want it to be.

  3. #3
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $path_parts=pathinfo($_FILES['uploadfile']['name']);
    $filename "images/newfilename.".$path_parts['extension']; 
    Saul


Bookmarks

Posting Permissions

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