我正在使用下面的代码来添加/编辑pdf,但它似乎根本不起作用。任何想法/帮助非常感谢。小号
if (is_uploaded_file($_FILES['pdfFile']['tmp_name'])) {
$format = strtolower(substr(strrchr($_FILES['pdfFile']['name'],"."),1));
$str = strtolower(trim($_FILES['pdfFile']['name']));
$str = preg_replace('/[^a-z0-9-]/', '-', $str);
$str = preg_replace('/-+/', "-", $str);
$pdfFileName=$str.'.'.$format;
$pdfUploadFile=$pdfFileDir.$pdfFileName;
$format!='pdf' ? $error='Invalid format uploaded for PDF File!<br />Please only upload files with the ".pdf" extension.' : NULL;
if (!$error && move_uploaded_file($_FILES['pdfFile']['tmp_name'], $pdfUploadFile)){
if($_POST['docFilename'] && file_exists($pdfFileDir.'/'.$_POST['docFilename'])) {unlink($pdfFileDir.'/'.$_POST['docFilename']);}
$_POST['docFilename']=$pdfFileName;
mysql_query("INSERT INTO table(docFilename, assoc_cat, assoc_object) VALUES('".$_POST['docFilename']."', '".$_POST['categoryID']."', '".$_POST['id']."')");
} else {
file_exists($pdfUploadFile) ? unlink($pdfUploadFile) : NULL;
!$error ? $error='The chosen PDF file failed to upload correctly.<br />Please try again, or attempt to upload an alternative PDF.' : NULL;
}
}
答案 0 :(得分:1)
确保为:
指定正确的设置请参阅:
同时确保:
enctype="multipart"
form
print_r($_FILES);