我成功上传了一个PDF文件,但我无法上传到特定的命名上传内容:
在点击上传按钮之前,我收到通知:
Notice: Undefined index: myFile in C:\xampp\htdocs\PDF UPLOAD DEMO\Upload_PDF_Demo3.php on line 8
Notice: Undefined variable: error in C:\xampp\htdocs\PDF UPLOAD DEMO\Upload_PDF_Demo3.php on line 9
Notice: Undefined index: myFile in C:\xampp\htdocs\PDF UPLOAD DEMO\Upload_PDF_Demo3.php on line 11
Notice: Undefined index: myFile in C:\xampp\htdocs\PDF UPLOAD DEMO\Upload_PDF_Demo3.php on line 13
Notice: Undefined variable: uploads_dir in C:\xampp\htdocs\PDF UPLOAD DEMO\Upload_PDF_Demo3.php on line 15
Notice: Undefined variable: uploads_dir in C:\xampp\htdocs\PDF UPLOAD DEMO\Upload_PDF_Demo3.php on line 15
/*After Clicking on Upload Button*/
1.)Notice:Use of undefined constant UPLOAD_DIR - assumed 'UPLOAD_DIR' in C:\xampp\htdocs\PDF UPLOAD DEMO\Upload_PDF_Demo.php on line 20
2.)Notice: Use of undefined constant UPLOAD_DIR - assumed 'UPLOAD_DIR' in C:\xampp\htdocs\PDF UPLOAD DEMO\Upload_PDF_Demo.php on line 27
3.)Notice: Use of undefined constant UPLOAD_DIR - assumed 'UPLOAD_DIR' in C:\xampp\htdocs\PDF UPLOAD DEMO\Upload_PDF_Demo.php on line 34
这是我的代码
<?php
define("uploads","./");
//$uploads_dir = $_SERVER['DOCUMENT_ROOT'].'/uploads/';
$_FILES["myFile"]["error"];
if ($error == UPLOAD_ERR_OK)
{
$tmp_name = $_FILES["myFile"]["tmp_name"];
echo "".$tmp_name;
$name = $_FILES["myFile"]["name"];
echo "".$name;
move_uploaded_file($tmp_name, $uploads_dir."/".$name, $uploads_dir);
echo "".$tmp_name;
}
echo $_SERVER['DOCUMENT_ROOT'];
?>
<form action="Upload_PDF_Demo.php" method="post" enctype="multipart/form-data">
<input type="file" name="myFile">
<br>
<input type="submit" value="Upload">
</form>
点击上传按钮前的注意事项
点击上传按钮后的通知
我的计划的输出
答案 0 :(得分:1)
你必须在
之前检查请求中是否有文件if (!empty($_FILES['myFile']['name'])) {
define("uploads","./");
//$uploads_dir = $_SERVER['DOCUMENT_ROOT'].'/uploads/';
$_FILES["myFile"]["error"];
if ($error == UPLOAD_ERR_OK)
{
$tmp_name = $_FILES["myFile"]["tmp_name"];
echo "".$tmp_name;
$name = $_FILES["myFile"]["name"];
echo "".$name;
move_uploaded_file($tmp_name, $uploads_dir."/".$name, $uploads_dir);
echo "".$tmp_name;
}
echo $_SERVER['DOCUMENT_ROOT'];
}
<form action="Upload_PDF_Demo.php" method="post" enctype="multipart/form-data">
<input type="file" name="myFile">
<br>
<input type="submit" value="Upload">
</form>