This is a script for handling file uploads to server side storage. At the moment, the uploaded file filename is manipulated. When i look at my hard disk the file which i have uploaded has no extension, however, im trying to modify this script to retain the physical file extension.
Can anybody help?
Code: Select all
<?php
## Set up database connections
include("dbconnect.php");
require("redirectuser.php");
## Handle if data is submitted
## OK, lets get the uploaded data and insert it into the database
## Where $upFile is an array
if (isset($submit)) {
if (isset($fileupload) && $fileupload != "none") {
## Get variables for new filename in file store
## Daves vars, if you dont want them delete from here down:
$timestamp = time();
$filedir = "/OpenSA/Apache/htdocs/final/files/work/";
## is getting the length of the temp file name of the uploaded file.
$len = strlen($HTTP_POST_FILESї'userfile']ї'name']);
## Here I cut from the end of the filename the last 3 chars which would be the extention for windows programs.
$ext = substr($HTTP_POST_FILESї'userfile']ї'name'],$len - 3,3);
$filenamenew = strtolower(str_replace(" ", "", $module_title)) . "-" . $timestamp . "." . $ext;
$filestore = $filedir . $filenamenew;
## Copy function is used to copy the file from temp store before placing into permanent store
if (!@copy($fileupload, $filestore)) {
echo "There was a problem copying the temporary file to a permenant store.";
exit;
}
## n12br Returns string with '<br />' (HTML line breaks) inserted before all newlines.
$filedesc = addslashes(nl2br($filedesc));
$sql = "INSERT INTO coursework_table";
$sql .= "(coursework_id, description, fileloc, filename, filesize, filetype, user_id, submission_time, module_title) ";
$sql .= "VALUES ('$courswork_id', '$filedesc', '$filestore', '$filenamenew', ";
$sql .= "'$fileupload_size', '$fileupload_type', '$mycookie', NOW(), '$module_title')";