简体   繁体   English

PHP:无法上传文件

[英]PHP: File upload won't work

I'm having trouble making file uploads with my PHP code. 我无法使用PHP代码上传文件。 I've checked out a few tutorials and some debug tips and advice (on here and off here), but nothing is working. 我已经检查了一些教程以及一些调试技巧和建议(在这里和在这里关闭),但是没有任何效果。 print_r($_FILES) yields no results. print_r($ _ FILES)没有结果。 Here's my HTML code: 这是我的HTML代码:

<form action="admin_avatars.php" method="post" enctype="multipart/form-data">
    <p>Image: <input type="file" name="avatar" id="avatar" /></p>
    <p class="buttonset"><input type="submit" value="Upload" /></p>
</form>

And here's my PHP code (with an ini_get just to make sure my file_uploads is set to "on"): 这是我的PHP代码(带有ini_get只是为了确保我的file_uploads设置为“ on”):

print("[ini get: ".ini_get("file_uploads")."]<br />");
print("[".$_FILES["avatar"]["name"]. "==".$_FILES["avatar"]["tmp_name"]."]<br />");

And, for this, I get the output: 而且,为此,我得到了输出:

[ini get: 1]
[==]

Kinda stumped at this point why nothing is uploading or why $_FILES isn't being filled with anything. 此时,Kinda感到困惑,为什么没有上载内容,或者为什么$ _FILES没有充满任何内容。 What small detail am I missing? 我缺少什么小细节?

Thanks! 谢谢!

Ok, for some reason it suddenly works. 好的,由于某种原因,它突然起作用了。 And I'm not sure why. 我不确定为什么。 All the elements that I can see remain the same, but here's my PHP code (PHP is the only thing I changed): 我可以看到的所有元素都保持不变,但这是我的PHP代码(PHP是我唯一更改的内容):

if($_FILES["character_image"]["name"] <> "") {
    $newfilename = $directory_characters . "/" . createfilename($_REQUEST["character_name"]) . "." . pathinfo($_FILES["character_image"]["name"], PATHINFO_EXTENSION);
    $imagesizeinformation = getimagesize($_FILES["character_image"]["tmp_name"]);
    copy($_FILES["character_image"]["tmp_name"], $newfilename);
}

Just in case, here's my HTML code at its barest: 以防万一,下面是我的HTML代码:

<form action="admin_characters.php" method="post" enctype="multipart/form-data">
    Image: <input type="file" name="character_image" id="character_image" />
    <p class="buttonset"><input type="submit" value="Add" /></p>
</form>

If anybody knows what fixed my problem, please let everyone know. 如果有人知道什么解决了我的问题,请告诉大家。 I'm stumped what happened here that suddenly allowed the images to come through. 我很困惑这里发生的事情突然使图像通过。

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

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