文件未上传 PHP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10807280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:05:42  来源:igfitidea点击:

File not uploading PHP

phpfileupload

提问by Michael Roewin Tan

I've attempted to write code to have a file uploaded to a "media" folder in PHP. For some reason it continues to not work.

我试图编写代码将文件上传到 PHP 中的“媒体”文件夹。由于某种原因,它继续不起作用。

Here's the execution code:

下面是执行代码:

move_uploaded_file($_FILES["file"]["tmp_name"],"../media/" . $_FILES["file"]["name"]) or die ("Failure to upload content");

Here's my form code:

这是我的表单代码:

    <input type="file" name="file" id="file" /> 

Any ideas why it may not be working?

任何想法为什么它可能不起作用?



EDIT:

编辑:

When I use the command "print_r($_FILES);", it displays:

当我使用命令“print_r($_FILES);”时,它显示:

Array ( [file] => Array ( [name] => Screen Shot 2012-05-29 at 12.36.11 PM.png [type] => image/png [tmp_name] => /Applications/MAMP/tmp/php/phpHNj3nW [error] => 0 [size] => 71640 ) )

Array ( [file] => Array ( [name] => Screen Shot 2012-05-29 at 12.36.11 PM.png [type] => image/png [tmp_name] => /Applications/MAMP/tmp/php/ phpHNj3nW [错误] => 0 [大小] => 71640 ) )

Image is NOT uploaded into the folder.

图像未上传到文件夹中。

回答by Michael Roewin Tan

Make sure that in your form.. you put the enctype.
eg: <form method="post" enctype="multipart/form-data" action="index.php"></form>;

确保在您的表单中.. 您放置了 enctype。
例如:<form method="post" enctype="multipart/form-data" action="index.php"></form>;

To check if files are successfully updated upon submitting the form. use print_r to see results.
print_r($_FILES);

在提交表单时检查文件是否已成功更新。使用 print_r 查看结果。
print_r($_FILES);

回答by mgraph

make sure mediafolder has 777 permission and the path ../media/is correct

确保 media文件夹具有 777 权限且路径../media/正确

回答by SuReSh

Put the encription in form

把文字写成表格

<form method="post" action="index.php" enctype="multipart/form-data"></form>

Check in php.ini file max_execution_timeheavy images are not uploaded due to execution time..

签入 php.ini 文件max_execution_time重图片由于执行时间未上传..

回答by Bala Krishnan

Check in php.ini file max_execution_time heavy images are not uploaded due to execution time..

签入php.ini文件max_execution_time重图片由于执行时间没有上传..

eg: ;

例如:

回答by Andrea V. Abbondanza

There is a form with encrypt type or an ajax call? Do you check if the file is sended to the upload script (with a print_r($_FILES["file"]). If correct, do you have check if the relative path is correct? You must start from the current script (if file is included you must start from the including script). Sorry if answer seems simply, but the posted code is a little too short to evaluate.

有加密类型或ajax调用的形式吗?您是否检查文件是否已发送到上传脚本(带有print_r($_FILES["file"])。如果正确,您是否检查相对路径是否正确?您必须从当前脚本开始(如果包含文件,则必须从包含脚本开始)。对不起,如果答案看起来很简单,但发布的代码有点太短而无法评估。

回答by Celeritas

In your form tag you want something like this <form enctype="multipart/form-data" action="uploader.php" method="POST">Make sure enctype is set to multipart/form-data for files. Replace uploader.php with the name of the php file doing the processing. Also make sure your permissions are set so the file can be created in the directory.

在你的表单标签中,你想要这样的东西 <form enctype="multipart/form-data" action="uploader.php" method="POST">确保文件的 enctype 设置为 multipart/form-data。将 uploader.php 替换为执行处理的 php 文件的名称。还要确保设置了您的权限,以便可以在目录中创建文件。

Here's a list of possible problems: http://php.net/manual/en/features.file-upload.php

以下是可能的问题列表:http: //php.net/manual/en/features.file-upload.php

回答by awadhesh

I was having the same problem. I am using ubuntu 18.04 and it was solved when i used this permission command on terminal. sudo chmod -R 777 /var/www/html/target_dir. ->I have apache2 web server and target_dir as Download so replace target_dir as per your destination directory.

我遇到了同样的问题。我使用的是 ubuntu 18.04,当我在终端上使用这个权限命令时它解决了。 须藤 chmod -R 777 /var/www/html/target_dir。->我有 apache2 Web 服务器和 target_dir 作为下载,因此根据您的目标目录替换 target_dir。

回答by Afsal Mt

Make sure that in your form.. you put the enctype.

确保在您的表单中.. 您放置了 enctype。

move_uploaded_file($file_tmp,"images/".$file_name);
echo "Success

回答by davidgo

Have you checked that the "web server user" has write permissions to "../media" ?

您是否检查过“网络服务器用户”是否具有对“../media”的写入权限?