本文介绍了如何使用jQuery AJAX和PHP实现文件上载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

imageUpload.html



imageUpload.html

<html>
<head>
<script src="../js/jquery-1.11.1.min.js"></script>

</head>
<body>
<div id="project_features" class="project_features">
        <form action="uploader.php" enctype="multipart/form-data">
                <label for="file">Featured Image:</label>
                <input type="file" name="myfile[]" multiple="multiple" id="featured_image"><br>

        <input type="submit" id="submit" value="Submit" />
                     </form>
    </div>
</body>
</html>







uploader.php






uploader.php

<?php


$upload_dir = "uploaded_files/images/";

if (isset($_FILES["myfile"])) {
    $no_files = count($_FILES["myfile"]['name']);
    for ($i = 0; $i < $no_files; $i++) {

        if ($_FILES["myfile"]["error"][$i] > 0) {
            echo "Error: " . $_FILES["myfile"]["error"][$i] . "<br>";
        } else {
            $temp = explode(".", $_FILES["myfile"]["name"][$i]);
            $extension = end($temp);
                 move_uploaded_file($_FILES["myfile"]["tmp_name"][$i], $upload_dir . $_FILES["myfile"]["name"][$i]);
                echo "<br><font color='green'>".$_FILES["myfile"]["name"][$i] . " Uploaded Successfully.</font><br>";
        }
    }
}
?>







此代码将多个图像存储在所需的文件夹中。但是如何使用jQuery和Ajax执行相同的功能?请帮我解决这个问题!




This code is storing the multiple Images in required folder.But How can I do the same functionality using jQuery and Ajax?Please help me sort this one out!

推荐答案




这篇关于如何使用jQuery AJAX和PHP实现文件上载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 21:12