douji8017
douji8017
2013-12-27 16:35

dropzone.js:如何重命名文件?

已采纳

I want to rename a file uploaded with dropzone.js. I have read the other question of rename file with dropzone, but I don't understand.

I've tried this:

this.on("sending", function(file, xhr, formData) { 
    var abdocument.getElementById("a").value
    var nick = document.getElementById("b").value;
    formData.append("fileName", a+ " - " + b);
    });
  }
};

but then how can I use this "fileName"? I've to use in php function? This is mine:

<?php

$upload_folder = 'uploads';
if (!empty($_FILES)) {
  $temp_file = $_FILES['file']['tmp_name'];
  $target_path = dirname( __FILE__ ) .  '/' . $upload_folder . '/';
  $target_file =  $target_path . $_FILES['file']['name'];


  if( file_exists( $target_path ) ) {
    move_uploaded_file($temp_file, $target_file);
  } else {
    header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
  }
}

?>

or can I rename via javascript?

Thanks to all

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • doushan7997 doushan7997 8年前

    Ok, I have to do this:

    $_FILES['file']['name'] = ($_POST["fileName"]);

    点赞 9 评论 复制链接分享
  • duanaoreng9355 duanaoreng9355 8年前

    simply set it at $_FILE superglobal as follow:

     $_FILES['file']['name']="your_new_file_name";
    
    点赞 评论 复制链接分享

相关推荐