使用 MAMP 上传 4kb 文件

发布于 2024-10-15 16:39:58 字数 1096 浏览 6 评论 0原文

我正在尝试使用 MAMP(OS X 上为 1.9.4)上传文件。 我使用这个脚本我在这里找到

这是表单代码:

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

uploader.php 代码:

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

uploads 文件夹确实存在,但当我提交表单时,出现以下错误:

There was an error uploading the file, please try again!

如何解决此问题? 谢谢,

问候。

编辑:在 phpinfo (5.3.2) 中,文件上传处于“打开”状态。

I'm trying to upload a file with MAMP (1.9.4 on OS X).
I use this script I found here :

Here is the form code:

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

And the uploader.php code:

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

The uploads folder does exist but when I submit my form, I get the following error:

There was an error uploading the file, please try again!

How can I resolve this?
Thanks,

Regards.

EDIT: In phpinfo (5.3.2), File upload is 'on'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

留一抹残留的笑 2024-10-22 16:39:58

我找到了解决办法!

我尝试并使用了 $HTTP_POST_FILES,而不是使用 $_FILES
我使用了复制函数,而不是move_uploaded_file

谁能给我解释一下吗?

谢谢。

I found a solution!

instead using $_FILES, I tried and used $HTTP_POST_FILES.
And instead move_uploaded_file, I used the copy function.

Can anyone give me an explanation?

Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文