php文件上传错误
我有个错误。我用HTML5和PHP上传了一个文件。当我尝试上传任何东西时,总会出现错误。代码如下:php文件上传错误,php,html,Php,Html,我有个错误。我用HTML5和PHP上传了一个文件。当我尝试上传任何东西时,总会出现错误。代码如下: <form action="upload.php" method="post" enctype="multipart/form-data"> Select file to upload: <input type="file" name="fileToUpload" id="fileToUpload"> <input type="submit"
<form action="upload.php" method="post" enctype="multipart/form-data">
Select file to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload your file" name="submit">
</form>
如注释中所述,逻辑测试中使用的变量没有在任何地方定义。我相信你是有意这样做的
<form action="upload.php" method="post" enctype="multipart/form-data">
Select file to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload your file" name="submit">
</form>
<?php
$target_path = "upload/";
$target_file = $target_path . basename( $_FILES["fileToUpload"]["name"] );
if( isset($_POST["submit"]) ) {
if ( file_exists( $target_file ) ) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
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.";
}
}
?>
选择要上载的文件:
只需更改移动上传文件调用的目标部分中的文件名
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))
如果(file_exists($target_file)){,您最初在哪里定义在
中使用的$target_file
?我认为您需要在那里使用$target_path
!此外,您应该在问题中包含错误,而不仅仅是“总是有错误”请遵循我希望对您有用的链接。只需更改move_uploaded_file调用的目标部分的文件名if(move_uploaded_file($_FILES[“fileToUpload”][“tmp_name”],$target_file))
仍然不起作用。可能与我的RPI服务器无关,但我认为SOI仍然不起作用。可能与我的RPI服务器无关,但我不这么认为。
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))