【发布时间】:2018-04-19 11:52:44
【问题描述】:
我正在尝试上传文件,但我不断收到发送到未找到对象的页面错误 404。
我猜这是因为我的路径目录错误,并且在 'localhost' 和 C:\xampp\htdocs\PHP 之间存在错误
提前致谢
我的 PHP 代码
<?php
$target_dir = "..\upload";
$target_file = $target_dir.basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$uploadError = "Error";
$fileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submit"])) {
$uploadOk = 1;
}
if (file_exists($target_file)) {
$uploadOk = 0;
$uploadError = "Sorry, file already exists.";}
if ($_FILES["fileToUpload"]["size"] > 100000) {
$uploadOk = 0;
$uploadError = "Sorry, your file is too large.";}
if($fileType != "txt" ) {
$uploadOk = 0;
$uploadError = "Sorry, only NOW TXT files are allowed.";}
if ($uploadOk == 0) {
echo $uploadError;} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}}?>
我的 HTML
<form action=".php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Submit" name="submit">
</form>
【问题讨论】: