Jump to content


PHP how to change/fetch image file name

php filename image thumbnail javascript

Best Answer jade24, 03 June 2013 - 02:30 PM

I've figured it out. I change the $RandomNumber to $ImageName. It works. Thanks for the help. 

Go to the full post

  • Please log in to reply
2 replies to this topic

#1 jade24

  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 03 June 2013 - 01:32 PM

I am new to php and I've downloaded a free source code for image gallery. It has admin account and you can upload image on it. Now when I upload image it generates random image title like numbers '4849404'. I want it to assign a specific title per image or just simply fetch the file name of the uploaded image and assign it as the title. How can I do that? here is the code.... 

$RandomNumber   = rand(0, 9999999999); // We need same random name for both files.

// some information about image we need later.
$ImageName      = strtolower($_FILES['ImageFile']['name']);
$ImageSize      = $_FILES['ImageFile']['size']; 
$TempSrc        = $_FILES['ImageFile']['tmp_name'];
$ImageType      = $_FILES['ImageFile']['type'];
$process        = true;

//Validate file + create image from uploaded file.
    case 'image/png':
        $CreatedImage = imagecreatefrompng($_FILES['ImageFile']['tmp_name']);
    case 'image/gif':
        $CreatedImage = imagecreatefromgif($_FILES['ImageFile']['tmp_name']);
    case 'image/jpeg':
        $CreatedImage = imagecreatefromjpeg($_FILES['ImageFile']['tmp_name']);
        die('Unsupported File!'); //output error

//get Image Size

//get file extension, this will be added after random name
$ImageExt = substr($ImageName, strrpos($ImageName, '.'));
$ImageExt = str_replace('.','',$ImageExt);
$BigImageMaxWidth       = $CurWidth;
$BigImageMaxHeight      = $CurHeight;

//Set the Destination Image path with Random Name
$thumb_DestRandImageName    = $Thumb.$RandomNumber.'.'.$ImageExt; //Thumb name
$DestRandImageName          = $DestinationDirectory.$RandomNumber.'.'.$ImageExt; //Name for Big Image

//Resize image to our Specified Size by calling our resizeImage function.
    //Create Thumbnail for the Image

    //respond with our images
    echo '<table width="100%" border="0" cellpadding="4" cellspacing="0">
        <tr><td align="center"><img src="gallery/'.$RandomNumber.'.'.$ImageExt.'" alt="Resized Image"></td></tr></table>';

    die('Resize Error'); //output error

#2 DaveyK

  • Members
  • PipPipPip
  • Advanced Member
  • 289 posts
  • LocationThe Netherlands

Posted 03 June 2013 - 01:42 PM

You can actually store the path to the image in a database and have both the random number as a file name AND a display title if you need it.


Also, the name of the image is defined by $RandomNumber.

#3 jade24

  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 03 June 2013 - 02:30 PM   Best Answer

I've figured it out. I change the $RandomNumber to $ImageName. It works. Thanks for the help. 

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users