小编Sec*_*ure的帖子

如何在codeigniter中使用ajax上传图像?

我正在尝试使用jQuery和ajax函数上传图像,如何获取图像文件的所有细节,就像我们使用的php一样 $_FILE()

这是我的代码

JS

$("#uploadimg" ).click(function() {
     $( "#file" ).click();
});

$( "#file" ).change(function(e) {
    var file=$('#file').val();
    alert(file);
    die();
    e.preventDefault();
    $.ajax({
        url:'http://localhost/JSG/blog/uploadimg',
        secureuri:false,
        type: "POST",
        fileElementId:'image',
        dataType: 'text',
        data:{ file: file },
        cache: true,
        success: function (data){
            alert(data);
            console.log(data);
        },
    });
});
Run Code Online (Sandbox Code Playgroud)

调节器

public function uploadimg()
{
    $var = $_POST['file'];
    print_r($var);
    if($this->input->post('file')) {
        $config['upload_path'] = 'upload'; 
        $config['file_name'] = $var;
        $config['overwrite'] = 'TRUE';
        $config["allowed_types"] = 'jpg|jpeg|png|gif';
        $config["max_size"] = '1024';
        $config["max_width"] = '400';
        $config["max_height"] = '400';
        $this->load->library('upload', $config);

        if(!$this->upload->do_upload()) {
            $this->data['error'] = …
Run Code Online (Sandbox Code Playgroud)

php ajax jquery codeigniter

5
推荐指数
1
解决办法
3万
查看次数

如何在php中显示blob类型的图像?

我正在尝试显示图像,但图像类型是blob.

题:

如何显示blob数据类型图像?

我尝试过:

function getBlob() {
     $data = $this->user_model->getBlob();
     echo "<img src="base64_encode( $data['IMAGE'] )">";
}
Run Code Online (Sandbox Code Playgroud)

但是不起作用.

php mysql data-uri-scheme

3
推荐指数
1
解决办法
171
查看次数

如何从ajax函数获取返回值到变量?

我正在调用一个函数,我希望得到一些价值.但我没有任何价值.

我该如何使用返回值?

$(function () {
    $(".datepicker").datepicker({
        beforeShowDay: function (date) {
            var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
            return [array.indexOf(string) == -1]
            console.log(array.indexOf(string) == -1);
        }
    });
});
var BDate = gateDateBooking(); // Calliing a function 
var BookingDate = Bdate; // But i did't get any responce here
function gateDateBooking(){
    $.ajax({
        url: "localhost/CodeIgniter_2.2.0/index.php/admin/GetBookingDate",
        type: "POST",
        dataType: "text",
        cache: false,
        success: function (data) {
           alert(data);
          return data; // return responce 
       }
   });
 }
Run Code Online (Sandbox Code Playgroud)

ajax jquery

0
推荐指数
1
解决办法
8457
查看次数

标签 统计

ajax ×2

jquery ×2

php ×2

codeigniter ×1

data-uri-scheme ×1

mysql ×1