我在将 PDF 文件保存到服务器上的文件夹时遇到问题。该代码一次有效,但现在无效。我想要它做的是检查是否有人在提交表单时尝试上传 PDF,如果文件字段中有 PDF,它会上传它,然后将路径保存到 mysql 数据库。代码如下:
if (!empty($_FILES['pdf'])){
$idir = "../files/PDF/"; //my directory file is supposed to be saved in
$randomd=rand(0000000,9999999); //creates a random number as filename
$domain = "http://".$_SERVER['HTTP_HOST'];
$file_ext = strrchr($_FILES['pdf']['name'], '.'); grabs file extension. my code checked if the file was a pdf a different way and neither seems to work.
$destination=$randomd.$file_ext; //new filename
if ($file_ext=='pdf') {
move_uploaded_file($_FILES['pdf']['tmp_name'], "$idir" . $destination);
$pdf= $domain."/files/PDF/".$destination; } else { echo("File type not supported.");
mysql_query("UPDATE tbl_listings SET pdf='$pdf' WHERE listing_id='$lid'");
}
if not empty 不起作用,它总是尝试上传文件,但是当我检查文件夹时,里面什么都没有,它不会更新 mysql。