我有以下代码。 的的index.php
<!DOCTYPE html>
<html>
<title>File Sharing</title>
<body>
<h1>File Sharing</h1><br/><br/>
<form action="upload.php" method="get" enctype="multipart/form-data">
Select File to Share:
<input type="file" name="file" id="file"/>
<button type="submit" name="submit" value="submit" id="submit" >Share</button>
</form>
<br/>
<p><a href="download.php"> or view shared files </a></p>
</body>
</html>
和upload.php
<?php
if(isset($_FILES['file'])){
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
$uploadOk = 1;
// Check file size
if ($_FILES["file"]["size"] > 50000000000000000000000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["file"]["name"]). " has been shared.<br/>";
echo "<br/><p><a href='index.php'>Go Back</a>or<a href='download.php'>View Shared files</a></p>";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
else{
echo"error uploading";
}
?>
以上我的文件不会上传。并给出“错误上传”我为这个问题提出了很多问题我尝试了所有但是没有解决我的问题。什么是错误???
答案 0 :(得分:2)
您使用了错误的表单方法。你不能&#34; GET&#34;数据到您的服务器。你必须&#34; POST&#34;它
http://bytes.com/topic/php/insights/664241-using-html-forms-pass-data-php
斯科特
答案 1 :(得分:1)
我的朋友你应该用POST替换你的GET方法 否则代码工作正常
<form action="upload.php" method="post" enctype="multipart/form-data">
Select File to Share:
<input type="file" name="file" id="file"/>
<button type="submit" name="submit" value="submit" id="submit" >Share</button>
</form>