I am using the following code to upload files limited to zip or rar, upon upload I have it set to rename the uploaded files to the id of the record placed in the database adding the file extension onto that.
Problem is that it leaves the file extension off ie
no file extension on the uploaded file.
also when it inserts the data (filename) into the database the file extension is marked as ie
I am wanting to have a page that allows people to download the files using links and need the file extensions to be ie
depending on the file type uploaded.
How to solve this?
$file_dir = "files";
$counter = 0;
$allowed_file_types = array(
'application/x-zip-compressed' => 'x-zip-compressed');
$file = $_FILES['file'];
while($counter <= count($file))
if($file['size'][$counter] > 0)
echo 'File '.($counter+1).' is not a accepted file type!<br />';
@mysql_query("INSERT INTO filename (filename) VALUES ('0')");
$new_id = mysql_insert_id();
$filetype = $file['type'][$counter];
$extention = $allowed_file_types[$filetype];
$filename = $new_id.".".$extention;
@mysql_query("UPDATE filename SET modelid='".$_GET['modelid']."', filename='".$filename."', userid='".$_SESSION['userid']."' WHERE fileid='".$new_id."'");
$newfile = $file_dir.'/'.$filename[$counter];