【发布时间】:2016-12-21 15:03:51
【问题描述】:
我正在尝试使用 PHP 在服务器中上传文件,但我遇到了一些问题。我找到了这个指南:http://www.sumedh.info/articles/store-upload-image-postgres-php-2.html。 我的html是:
<form action="img_user.php" method="POST" enctype="multipart/form-data" >
<button id="buttonImgProf" class="btn" type="button" onclick="caricaImgProf()">Inserisci un immagine</button>
<div id="imgProfLoader" class="postContent" style="display:none;">
Name : <input type="text" name="name" size="25" length="25" value="">
<input type="file" name="userfile"></input>
<button class="btn" type="submit">Carica immagine</button>
</div>
</form>
(部分不显示,因为我使用 javascript)。 php代码为:
$uploaddir = 'localhost'; //i have try lots of dir, maybe the error is here?
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$name = $_POST['name'];
echo $_FILES['userfile']['tmp_name'];
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{ echo "File is valid, and was successfully uploaded.\n";
}
else { echo "File not uploaded"; }
输出是File not uploaded
【问题讨论】:
-
请不要用您在答案中发布的代码覆盖您的问题代码。那应该是一个编辑并标记为 EDIT:.... 我试过的”。
标签: php html sql database localhost