我想同時上傳圖片和PDF,但它給出了錯誤。我不知道我錯過了什麼,圖片上傳得當,但上傳pdf時出現問題。 這是一段代碼。上傳時未獲取文件類型和tmp_name
<pre>
<?php
if ($_GET["action"] == "submit") {
$imageType="press_release_image_";
$ext= substr(basename($_FILES['brwAddNews']['name']),-4);
$filename=$imageType.$ext;
$target_path = $filename;
$pdfType="press_release_pdf_";
$pdfext= substr(basename($_FILES['brwAddNewsPdf']['name']),-4);
$pdffilename=$pdfType.$pdfext;
$pdf_target_path = $pdffilename;
print_r($_FILES) ;
$pdfext= substr(basename($_FILES['brwAddNewsPdf']['name']),-4);
if($pdfext==".pdf"){
if(move_uploaded_file($_FILES['brwAddNews']['tmp_name'], $target_path) && move_uploaded_file($_FILES['brwAddNewsPdf']['tmp_name'], $pdf_target_path))
{
echo "file uploaded";
}
else echo "Not uploaded";
}
else echo "Its not a pdf file";
}
?>
<center>
<form action="try.php?action=submit" method="post" enctype="multipart/form-data" name="frmNews" id="frmNews" >
<table><tr><td>NAME :<td/><td><input name="news_name" type="text" class="textfield" id="news_name" value="" /><br></td></tr>
<tr><td>PDF : <td/><td><input name="brwAddNewsPdf" type="file" id="brwAddNewsPdf" multiple="multiple" /><br></td></tr>
<tr><td>IMAGE : <td/><td><input name="brwAddNews" type="file" id="brwAddNews" multiple="multiple"/><br></td></tr>
<tr><td><td/><td><input name="btnSave" type="submit" class="buttons" id="btnSave" value="Save"></td></tr>
</form>
</center>
我得到輸出:
Array
(
[brwAddNewsPdf] => Array
(
[name] => Newsletter-volume16.pdf
[type] =>
[tmp_name] =>
[error] => 1
[size] => 0
)
[brwAddNews] => Array
(
[name] => PDF-thumbnail.jpg
[type] => image/jpeg
[tmp_name] => /tmp/php0KuLSj
[error] => 0
[size] => 4536
)
)
Not uploaded
可能是什麼問題?我錯過了什麼?
http://www.php.net/support。php – hakre