ColdEdge Posted November 18, 2009 Share Posted November 18, 2009 Hi, I made a PHP upload script that uploads image and adds extra things to the name.Here is the codeThe problem is that the image is upload however if the image name is say 59.png it will be upload as bf6-gsiu5cztf3ci_706h8m121h but, I don't not know how to add extension so for a .png image a .png ext will be added to this so it will look like this: bf6-gsiu5cztf3ci_706h8m121h.png since I tried doing this method$ext = ".jpg";this adds the .jpg text to the end result but when saved onto a computer Photoshop for example dosen't read it as a valid .jpg file since the original file was .pngWhat can I do to echo the extensions?Using either $HTTP_POST_FILES['ufile']['type'] to get the mine type and making php convert it to required echo statement, or is there a different way?-Thx Link to comment Share on other sites More sharing options...
Ingolme Posted November 18, 2009 Share Posted November 18, 2009 Extract the extension from the original file name, which is given in $_FILES['ufile']['name'] Link to comment Share on other sites More sharing options...
ColdEdge Posted November 18, 2009 Author Share Posted November 18, 2009 the problem is that I don't know how... +this line of code renames the file into something random... $letters = '0123456789abcdefghijklm0123456789nopqrstuvwxyz0123456789ABCDEFGHIKLM0123456789NOPQRSTUVWXYZ0123456789'; srand((double) microtime() * 1000000); $file_name = ''; for ($i = 1; $i <= rand(22,22); $i++) { $q = rand() %33; $file_name = $file_name . $letters[$q]; } Link to comment Share on other sites More sharing options...
kirbyweb Posted November 18, 2009 Share Posted November 18, 2009 Do you want it to make it random or not? Link to comment Share on other sites More sharing options...
Ingolme Posted November 18, 2009 Share Posted November 18, 2009 Right after the loop, you would just add $file_name = $file_name . "." . $ext; $ext is the file extension that's extracted from the original file name. Link to comment Share on other sites More sharing options...
ColdEdge Posted November 18, 2009 Author Share Posted November 18, 2009 nvm, got the extension to work ^^ Link to comment Share on other sites More sharing options...
justsomeguy Posted November 18, 2009 Share Posted November 18, 2009 You can get the extension using explode and pop:$ext = array_pop(explode('.', $_FILES['ufile']['name'])); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.