【问题标题】:Problems with a php form uploadphp表单上传的问题
【发布时间】:2014-10-19 18:34:06
【问题描述】:

我正在尝试通过表单和 php 文件上传文件。我在整个网站上多次使用相同的方法,没有任何问题,但是这次我无法让它工作。在我的表格上,我有这个....

<span class="purple"><strong>Upload Your Image</strong></span> 
<input name="userfile" type="file" id="userfile" class="textbox">
<br /><br />
<label>
    <input name="submit" type="submit" class="createbutton" id="submit1" value="ADD TO BASKET">
</label>

在我的 php 文件中,我有这个...

//upload image first

$uploaddir = '../images/';
$uploadfile = $uploaddir. $_FILES['userfile']['name'];
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    $status = 1;//uploaded
    $data["printfile"] = $_FILES['userfile']['name'];
} else {
    $status = 0;//cant upload
    echo "Upload Failed!\n";
    $err = "";
}

每次它只是给我上传失败错误消息。有什么想法吗?

【问题讨论】:

  • 你在
    中给 enctype 了吗?
  • 在哪里?
  • 你能把你的整个表格贴出来吗?
  • 如果你在 *nix 系统上,那么它 '../images/' 应该有 777 权限,如果一切都是正确的。除了这个!
  • 结帐stackoverflow.com/questions/22400067/…也许会有所帮助

标签: php forms file-upload upload


【解决方案1】:

啊,对了,我现在真的觉得自己像个傻瓜。我以某种方式设法错过了我的表单标签上的 enctype="multipart/form-data" 。非常感谢您的帮助,现在完美运行。

【讨论】:

    猜你喜欢
    • 2015-01-02
    • 2011-08-19
    • 2021-09-26
    • 1970-01-01
    • 1970-01-01
    • 2011-01-21
    • 2020-04-05
    • 2010-10-30
    相关资源
    最近更新 更多