This is the first time I've attempted to make a script to upload files. For some reason, I can't delete the files after I upload them. I'm assuming the problem is regarding chmod settings (I'm probably wrong).
When I try to delete one of the files I uploaded by FTP, it says permission denied. When I try to modify the chmod settings, it gives me the error, "Could not change perms on exam2_wans.pdf: Bad file descriptor"
Any ideas?
<?PHP
include ('includes/header.php');
if ($submit) {
$query="SELECT volume FROM volumes";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
$lastvol=0;
while ($i < $num) {
$volume=mysql_result($result,$i);
if ($volume > $maxvol)
{
$lastvol=$volume;
}
$newvol=$lastvol+1;
$i++;
}
mkdir("/home/andyk/public_html/pem/volumes/" . $newvol, 0777);
$pdfname=uploader(pdf,$newvol);
$query="INSERT INTO volumes (volume,volumetitle,volumepdf,date) VALUES ('$newvol', '$title', '$pdfname', '$date')";
$result=mysql_query($query);
}
include ('includes/newvolumeform.php');
function uploader($fieldname,$folder) {
$safe_filename = clean_filename($_FILES[$fieldname]['name']);
$full_path = "/home/andyk/public_html/pem/volumes/".$folder."/".$safe_filename;
$working_path = "/pem/volumes/".$folder."/".$safe_filename;
if (move_uploaded_file($_FILES[$fieldname]['tmp_name'], $full_path)) {
print $safe_filename.' successfully uploaded as '.$working_path;
//return working path
return $working_path;
} else {
return false;
}
}
function clean_filename($filename) {
$filename = str_replace('/','',$filename);
$filename = str_replace(' ','_',$filename);
$filename = str_replace('?','',$filename);
$filename = str_replace('!','',$filename);
$filename = str_replace('\'','',$filename);
$filename = str_replace('"','',$filename);
$filename = strtolower($filename);
return $filename;
}
include ('includes/footer.php');
?>