Jump to content

create file path with a variable


Lassie

Recommended Posts

I want to save an image with a unique name that is created from a hash function.

How can I cretae the path with the variable...

 

$hash=$_GET['hash'];
$path ="/Applications/MAMP/htdocs/test_upload/images/imagename2.png";
//becomes
$path ="/Applications/MAMP/htdocs/test_upload/images/'.$hash.'.png";?

 

Link to comment
https://forums.phpfreaks.com/topic/229251-create-file-path-with-a-variable/
Share on other sites

$hash = substr(md5(uniqid(rand(), true)), 0, 20);
$path = "/Applications/MAMP/htdocs/test_upload/images/".$hash.".png";
rename("/Applications/MAMP/htdocs/test_upload/images/imagename2.png", "/Applications/MAMP/htdocs/test_upload/images/".$hash.".png");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.