Jump to content

Please help with file extension


lingo5

Recommended Posts

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

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.