Jump to content

[SOLVED] Once file is uploaded, rename file?


coupe-r

Recommended Posts

Hey everyone.

 

My script works fine, I would like to know how to rename the file once it is uploaded.  For instance, if they upload green.jpg, I was to rename the file to their company name ($_SESSION['company']) . JPG.

 

if(is_uploaded_file($_FILES['file']['tmp_name'])) 
{
$ext = strtolower(substr(($t=strrchr($_FILES['file']['name'],"."))!=false?$t:'',1));

	if(!in_array($ext, $filetype))
	{
		$upload_error = '<FONT color="red"><b>Error:</b></FONT>' . '    ' . "Allowed filetypes: $ftype";
	}
		elseif($_FILES['file']['size'] > $max_size*1024)
		{
			 $upload_error = '<FONT color="red"><b>Error:</b></FONT>' . '    ' . "File is too big. Max file size 1 MB.";
		}
	else
	{
		$fn = substr($_FILES['file']['name'], 0, strrpos($_FILES['file']['name'], '.'));
		$f = $fn.".".$ext;

		if(move_uploaded_file($_FILES['file']['tmp_name'], $folder.$f))
		{
			mysql_query("INSERT INTO uploads VALUES(NULL, '/support/admin/uploads/".$_FILES['file']['name']."', '".$_SESSION['admin_id']."', '".$_SESSION['company']."', '".$_FILES['file']['name']."')");

			$uploaded = true;
			chmod($folder.$f, 0777);
                        }

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.