【发布时间】:2017-03-18 12:16:55
【问题描述】:
这里我想使用 jquery ajax 函数上传和移动 csv 文件。
$("#file").change(function() {
alert($("#file").val());
$.ajax({
url: "<?php echo base_url(); ?>index.php/Task_controller/upload_tasksquestion",
type: "post",
dataType: 'json',
processData: false,
contentType: false,
data: {file: $("#file").val()},
success: function(text) {
alert(text);
if(text == "success") {
alert("Your image was uploaded successfully");
}
},
error: function() {
alert("An error occured, please try again.");
}
});
});
我的html代码是:
< input type="file" class="form-control" id="file" name="file">
我正在测试控制器功能上传的文件名 比如 $this->input->post('file');
但它没有到达控制器,我想将该文件移动到一个文件夹中。 请帮助我在哪里做错了......
我的服务器端代码是:
$curdate=date('Y-m-d');
$path='./assets/fileuploads/';
$file=basename($_FILES['file']['name']);
list($txt, $ext) = explode(".", $file);
$actual_file_name = time().substr($txt, 5).".".$ext;
if(move_uploaded_file($_FILES['file']['tmp_name'],$path.$actual_file_name))
【问题讨论】:
标签: jquery ajax codeigniter