Reputation: 227
this is part of an image upload script i made. I decided to name the rename the images i upload to the time i upload.
date_default_timezone_set('UTC');
$mvTime = date("dmy").(date("H")+5).date("is");
$folder = "images/";
$tmp = imagecreatetruecolor($orig_w, $orig_h);
imagejpeg($tmp, $folder.$mvTime.'.jpg', 100);
now when i upload the image, it saves the image like 051112174700.jpg . its the date in dmyHis format. now i am confused how i show a preview of the image. because the time is changing all the time. thats why i cant use $folder.$mvTime.'jpg' in the tag src.
can any body help me how i can get the image ?
Upvotes: 2
Views: 74
Reputation: 5605
You defined the image location in the mvTime
, so use it like this?
date_default_timezone_set('UTC');
$mvTime = date("dmy").(date("H")+5).date("is");
$folder = "images/";
$tmp = imagecreatetruecolor($orig_w, $orig_h);
imagejpeg($tmp, $folder.$mvTime.'.jpg', 100);
echo '<img src="'.$folder.$mvTime.'.jpg" />'; // <---- added this
Upvotes: 2
Reputation: 4830
You know the path of the image already - $folder.$mvTime.'jpg'
.
It is not clear from your question but if you want to show a preview immediately after uploading then inside PHP you could do the following:
echo '<img src="'.$folder.$mvTime.'jpg" />";
Alternatively, you will need to come up with a naming convention that allows you to find the image you want later, or store information on the images somewhere (such as in a database).
Upvotes: 2
Reputation: 1674
you can use session for temporally save image names
date_default_timezone_set('UTC');
$mvTime = date("dmy").(date("H")+5).date("is");
$folder = "images/";
$tmp = imagecreatetruecolor($orig_w, $orig_h);
imagejpeg($tmp, $folder.$mvTime.'.jpg', 100);
$_SESSION['img_temp_name']=$mvTime.'.jpg';
Upvotes: 2