我有以下HTML代码:
<input type='file' multiple>
Run Code Online (Sandbox Code Playgroud)
这是我的JS代码:
var inputFiles = document.getElementsByTagName("input")[0];
inputFiles.onchange = function(){
var fr = new FileReader();
for(var i = 0; i < inputFiles.files.length; i++){
fr.onload = function(){
console.log(i) // Prints "0, 3, 2, 1" in case of 4 chosen files
}
}
fr.readAsDataURL(inputFiles.files[i]);
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,如何使这个循环同步?首先等待文件完成加载然后转到下一个文件.有人告诉我使用__CODE__.但我不能让它发挥作用.这是我正在尝试的:
var inputFiles = document.getElementsByTagName("input")[0];
inputFiles.onchange = function(){
for(var i = 0; i < inputFiles.files.length; i++){
var fr = new FileReader();
var test = new Promise(function(resolve, reject){
console.log(i) // Prints 0, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用codeigniter 3上传图像文件,但它无法正常工作.无论我做什么,它总是说"你没有选择要上传的文件".它在控制台上记录一个错误,当我点击网络选项卡中的错误然后它将我重定向到一个新的选项卡,其中显示错误时,错误500.这是我的HTML代码:
<div id="container">
<h1>Welcome to CodeIgniter!</h1>
<div id="body">
<form method="post" enctype="multipart/form-data" action="<?php echo base_url('index.php/welcome/upload'); ?>">
<input type="text" name="username" value="Zahid Saeed">
<input type="file" name="profile_img">
<button type="submit">Submit Form</button>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper("url");
}
public function index()
{
$this->load->view('welcome_message');
}
public function upload() {
$config = array(
"upload_path" => "./uploads/",
"allowed_types" => "gif|jpg|png"
);
echo "<pre>";
print_r($this->input->post());
print_r($_FILES);
echo "</pre>";
$this->load->library("upload", $config);
$this->upload->initialize($config);
if(!$this->upload->do_upload("profile_img")) { …Run Code Online (Sandbox Code Playgroud)