lingo5 Posted March 19, 2013 Share Posted March 19, 2013 Hi I have a script to upload an image and save the path to my DB. But I need to convert the file extension to lower acse before saving the path... here's my script $uploadDir = '../uploads/'; if(isset($_POST['upload'])) { foreach ($_FILES as $file) { $fileName = $file['name']; $tmpName = $file['tmp_name']; $fileSize = $file['size']; $fileType = $file['type']; if($fileName==""){ $filePath = '../uploads/img/none.jpg'; } else{ $filePath = $uploadDir . $fileName; } ////assigning random name //// get the file extension first $ext = substr(strrchr($fileName, "."), 1); //// make the random file name $randName = md5(rand() * time()); //// and now we have the unique file name for the upload file $filePath = $uploadDir . $randName . '.' . $ext; // Replace spaces with a '_' $filePath = str_replace(" ", "_", $filePath); $result = move_uploaded_file($tmpName, $filePath); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $fileinsert[]=$filePath; } thanks Link to comment https://forums.phpfreaks.com/topic/275880-please-help-with-file-extension/ Share on other sites More sharing options...
PaulRyan Posted March 19, 2013 Share Posted March 19, 2013 $ext = strtolower(substr(strrchr($fileName, "."), 1)); Link to comment https://forums.phpfreaks.com/topic/275880-please-help-with-file-extension/#findComment-1419635 Share on other sites More sharing options...
Zane Posted March 19, 2013 Share Posted March 19, 2013 Just strtolower() $filename foreach ($_FILES as $file) { $fileName = strtolower($file['name']); Link to comment https://forums.phpfreaks.com/topic/275880-please-help-with-file-extension/#findComment-1419637 Share on other sites More sharing options...
lingo5 Posted March 19, 2013 Author Share Posted March 19, 2013 thanks guys...both your solutions work fine !!! Link to comment https://forums.phpfreaks.com/topic/275880-please-help-with-file-extension/#findComment-1419641 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.