weixin_33713350 2017-04-20 09:43 采纳率: 0%
浏览 67

将文件图像上传到文件夹

Can someone help me how to upload image files to file using ajax This is form of me:

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

1条回答 默认 最新

  • weixin_33698823 2017-04-20 10:20
    关注

    Ajax call

    $.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 function

    $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
    
    评论

报告相同问题?