简体   繁体   English

PHP文件上传move_uploaded_file不起作用

[英]PHP file Upload move_uploaded_file not working

I am developing a web application with a file upload. 我正在开发一个具有文件上传功能的Web应用程序。

I just writted an php code to upload an image. 我只是写了一个php代码来上传图片。

if(isset($_FILES['equipmentPictureName'])){

 $file_tmp =$_FILES['equipmentPictureName']['tmp_name'];
 $file_name = $_FILES['equipmentPictureName']['name'];

 $uploads_dir = '/pic';
 echo "on file upload if";
 if(move_uploaded_file($file_tmp,$uploads_dir.$file_name)){
    echo "uploaded";
    exit();
 }else
 {
    echo "error on upload";
    exit();
 }  
 }else{
 echo "File Not Present";
 exit();
}   

When I run this code I can get output like on file upload if error on upload 当我运行此代码时, 如果上传错误,我可以得到类似文件上传的输出

I give 777 permission to pic folder 我授予777 图片文件夹许可

What is the issue, Any Idea,, 有什么问题,任何想法,

Form.. 形成..

<form action="manage-ahri-action.php" method="post" name="equipment" enctype="multipart/form-data" id="multiple_upload_form" >

  <div class="col-lg-6 col-sm-6 row" style="margin-bottom: 15px;">
                            <div class="form-group">
                                <label for="" class="col-lg-4 col-sm-4" style="text-align: right;">Equipment Picture</label>
                                <div class="col-lg-8 col-sm-8">
                                   <div class="option-group uploading none">
                                      <span class="file-button btn-primary" style="margin-right: 14px;">Choose File</span>
                                       <input name="equipmentPictureName" type="file" class="form-control form-white"/>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="file col-lg-12 col-sm-12 col-md-12">
                            <button type="submit" class="btn btn-primary btn-square" style="margin-top: 20px">Submit</button>
                        </div>

 </form>

Print_R 的print_r

Array ( [equipmentPictureName] => Array ( [name] => cat-01.jpg [type] => image/jpeg [tmp_name] => /tmp/php96PS5A [error] => 0 [size] => 72413 ) [accreditations] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [Brochures] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) ) Array([equipmentPictureName] => Array([name] => cat-01.jpg [type] => image / jpeg [tmp_name] => / tmp / php96PS5A [error] => 0 [size] => 72413)[认证] =>数组([名称] => [类型] => [tmp_name] => [错误] => 4 [大小] => 0)[手册] =>数组([名称] => [类型] = > [tmp_name] => [错误] => 4 [大小] => 0))

Thanks 谢谢

尝试对您的代码进行此修复:

$uploads_dir = '/pic/'; //Add another slash to complete the directory path

// Get the path to the upload directory. //获取上传目录的路径。

 $wp_upload_dir = wp_upload_dir();
$uploads_dir= $wp_upload_dir['url'] . '/pic/' ;

Try this : 尝试这个 :

if(isset($_FILES['equipmentPictureName']['name'])){

 $file_tmp =$_FILES['equipmentPictureName']['tmp_name'];
 $file_name = $_FILES['equipmentPictureName']['name'];

 $uploads_dir = 'pic/';
 echo "on file upload if";
$move=move_uploaded_file($file_tmp,$uploads_dir.$file_name);
 if($move){
    echo "uploaded";
    exit();
 }else
 {
    echo "error on upload";
    exit();
 }  
 }else{
 echo "File Not Present";
 exit();
}   

And make sure that this file and folder are at same location . 并确保此文件和文件夹位于同一位置 And the folder has 777 permission. 该文件夹具有777权限。

EDITED : 编辑:

OR instead of this main condition 或代替这个主要条件

if(isset($_FILES['equipmentPictureName']['name'])){

you can check using this, which means replace the line with this : 您可以使用它进行检查,这意味着用以下代码替换该行:

if($_FILES['file_equipmentPictureName']['name']!=''){

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

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