我试图上传文件,但我一直收到发送到找不到页面错误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>
答案 0 :(得分:1)
改变这个:
action=".php"
致:
action=""
(默认情况下重定向到当前页面)
404
表示在提交表单后找不到您重定向的页面。价值&#34; .php&#34;并不好。