【问题标题】:Upload file img into forder将文件图像上传到文件夹
【发布时间】:2017-04-20 09:43:23
【问题描述】:

有人可以帮我如何使用 ajax 将图像文件上传到文件 这是我的形式:

<form class="form-create" method="post">
     <input type="file" name="file" size="20" />
     <input type="button" name="submit" onclick="addproduct()" value="upload">
</form>

【问题讨论】:

标签: php ajax file-upload asyncfileupload


【解决方案1】:

Ajax 调用

$.ajax({
    url: "ajax_php_file.php", // Url to which the request is send
    type: "POST",             // Type of request to be send, called as method
    data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
    contentType: false,       // The content type used when sending data to the server.
    cache: false,             // To unable request pages to be cached
    processData:false,        // To send DOMDocument or non processed data file it is set to false
    success: function(data)   // A function to be called if request succeeds
    {
    $('#loading').hide();
    $("#message").html(data);
    }
    });

php函数

$sourcePath = $_FILES['file']['tmp_name'];       // Storing source path of the file in a variable
$targetPath = "upload/".$_FILES['file']['name']; // Target path where file is to be stored
move_uploaded_file($sourcePath,$targetPath) ;    // Moving Uploaded file

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-30
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 2014-10-24
    • 2020-01-10
    • 2021-09-29
    相关资源
    最近更新 更多