简体   繁体   English

PHP表单上传问题

[英]Problems with a php form upload

I am trying to upload a file via a form and a php file. 我正在尝试通过表单和php文件上传文件。 I have used the same method many times throughout my website with no problems, however this time I just can not get it to work. 我在我的网站上多次使用相同的方法,没有问题,但是这次我无法使用它。 On my form I have this.... 在我的表格上,我有这个...

<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>

In my php file I have this... 在我的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 = "";
}

Every time it just gives me the Upload Failed error message. 每次它只给我上载失败错误消息。 Any ideas? 有任何想法吗?

Ah right, I really feel like a fool now. 嗯,我现在真的很傻。 I somehow managed to miss enctype="multipart/form-data" on my form tag. 我以某种方式设法在表单标签上错过了enctype =“ multipart / form-data”。 Thanks so much for your help, works perfectly now. 非常感谢您的帮助,现在可以正常使用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM