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 Quote 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)); Quote Link to comment https://forums.phpfreaks.com/topic/275880-please-help-with-file-extension/#findComment-1419635 Share on other sites More sharing options...
Solution Zane Posted March 19, 2013 Solution Share Posted March 19, 2013 Just strtolower() $filename foreach ($_FILES as $file) { $fileName = strtolower($file['name']); Quote 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 !!! Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.