dongxikuo5171 2019-07-22 11:55
浏览 40
已采纳

FIle没有上传到同一服务器的另一个目录。

I want to upload file to an directory of another outside of my word-press directory.

Here is my HTML

<form>
<div class="form-group  upload-btn-wrapper2">
<span id="">Member Passport - Front</span>
<input required="" type="file" dir="rtl" name="member_passport_front_copy_names" id="member_passport_front_copy_names" class="form-control valid" for="UAE citizen" aria-required="true" aria-invalid="false">
</div>

</form>

Here is my AJAX Function.

   jQuery(document).ready(function () {

                jQuery('body').on('change', '#member_passport_front_copy_names', function (evt) {

                         var data = new FormData(this.form);
                          var data = new FormData();
        var files = jQuery('#member_passport_front_copy_names')[0].files[0];
        data.append('file',files);
                         jQuery.ajax({
                             url: '<?php echo site_url(); ?>/wp-admin/admin-ajax.php?action=cms_filesubmit',
                             type: "POST",
                             data: data,
                            mimeType: "multipart/form-data",
                            contentType: false,
                             processData: false,
                            cache: false,
                            dataType: "html",
                             success: function (response) {
                                  console.log(response);

                             },
                             error: function (response) { 
                             alert("something went wrong");
                             }
                         });


            });
                }); 

Here is my PHP function to upload file to directory

add_action( 'wp_ajax_cms_filesubmit', 'cms_filesubmit' );
add_action( 'wp_ajax_nopriv_cms_filesubmit', 'cms_filesubmit' );

function cms_filesubmit(){

$target_dir = "http://sajaya.ae/himmah/app/webroot/img/user_upload/";

if(isset($_FILES['file'])){
      $errors= array();
      $file_name = $_FILES['file']['name'];
      $file_size =$_FILES['file']['size'];
      $file_tmp =$_FILES['file']['tmp_name'];
      $file_type=$_FILES['file']['type'];
      $file_ext=strtolower(end(explode('.',$_FILES['file']['name'])));

      $extensions= array("jpeg","jpg","png");

      if(in_array($file_ext,$extensions)=== false){
         $errors[]="extension not allowed, please choose a JPEG or PNG file.";
      }

      if($file_size > 2097152){
         $errors[]='File size must be excately 2 MB';
      }

      if(empty($errors)==true){
         move_uploaded_file($file_tmp,"http://sajaya.ae/himmah/app/webroot/img/user_upload/".$file_name);
         echo "Success";
      }else{
         print_r($errors);
      }
   }
}

When ever i change or upload file it give in response Success but file not get uploaded to directory.

  • 写回答

1条回答 默认 最新

  • dtv8189 2019-07-22 12:17
    关注

    move_uploaded_file does not work with HTTP URLs – you need to specify a file system path for the destination.

    Either relative to the current working directory of your script, or as a full absolute path from the server file system’s root directory.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么apriori的运行时间会比fp growth的运行时间短呢
  • ¥15 帮我解决一下膳食平衡的线性规划模型的数据实例
  • ¥40 万年历缺少农历,需要和阳历同时显示
  • ¥250 雷电模拟器内存穿透、寻基址和特征码的教学
  • ¥200 比特币ord程序wallet_constructor.rs文件支持一次性铸造1000个代币,并将它们分配到40个UTXO上(每个UTXO上分配25个代币),并设置找零地址
  • ¥15 关于Java的学习问题
  • ¥15 如何使用chatgpt完成文本分类任务?
  • ¥15 已知速度v关于位置s的等式,怎么转化为已知位置求速度v的等式
  • ¥15 我有个餐饮系统,用wampserver把环境配置好了,但是后端的网页却进去,是为什么,能不能帮远程一下?
  • ¥15 R运行没有名称为"species"的插槽对于此对象类"SDMmodelCV"