我使用php上传并将文件移动到所需位置... 使用move_uploaded_file时,它表示文件已成功移动但该文件未显示在目录中。 HTML和PHP代码如下......
<form action="test_upload.php" method="POST" enctype="multipart/form-data">
<fieldset>
<label for="test_pic">Testing Picture</label>
<input type="file" name="test_pic" size="30" /><br />
</fieldset>
<fieldset>
<input type="submit" value="submit" />
</fieldset>
</form>
php就像:
<?php
$image_fieldname = "test_pic";
$upload_dir = "/vidit";
$display_message ='none';
if(move_uploaded_file($_FILES[$image_fieldname]['tmp_name'],$upload_dir) && is_writable($upload_dir)){
$display_message = "file moved successfully";
}
else{
$display_message = " STILL DID NOT MOVE";
}
?>
当我运行此页面并上传合法文件时 - test_upload.php回显成功上传的文件。但是当我前往网页根目录中的“vidit”文件夹时。该文件夹是空的......
我正在使用wamp服务器。
答案 0 :(得分:2)
您需要将文件名附加到目标路径。请尝试以下
$doc_path = realpath(dirname(__FILE__));
if(move_uploaded_file($_FILES[$image_fieldname]['tmp_name'],$doc_path.$upload_dir.'/'.$_FILES[$image_fieldname]['name']) && is_writable($upload_dir)){
$display_message = "file moved successfully";
}
else{
$display_message = " STILL DID NOT MOVE";
}
请参阅PHP手册以供参考。 http://php.net/manual/en/function.move-uploaded-file.php
答案 1 :(得分:0)
使用它可能有效
$upload_dir = "vidit/";
$uploadfile=($upload_dir.basename($_FILES['test_pic']['name']));
if(move_uploaded_file($_FILES['test_pic']['tmp_name'], $uploadfile) ) {
}
答案 2 :(得分:0)
<?php
$image_fieldname = "test_pic";
$upload_dir = "/vidit";
$display_message ='none';
if (move_uploaded_file($_FILES[$image_fieldname]['tmp_name'],$upload_dir . '/' . $_FILES[$image_fieldname]['name'] && is_writable($upload_dir)) {
$display_message = "file moved successfully";
} else {
$display_message = " STILL DID NOT MOVE";
}
?>
还添加了缩进。需要应用文件名,或者就像将文件上传为无扩展名文件一样。
答案 3 :(得分:0)
在root(www)中创建tmp目录,并确保更改目录路径 /您的目录名称是强制性的
$ upload_dir = $ _SERVER [&#39; DOCUMENT_ROOT&#39;]。&#39; / tmp /&#39;;