How can i upload image with ajax in codeigniter?

前端 未结 4 788
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 06:46

I\'m trying to upload image with jQuery and ajax function, and how can I fetch all details of image file, like in php we use $_FILE()

Here is my code

4条回答
  •  醉梦人生
    2020-12-16 07:21

    You can get seamless functionality if you use this plugin (well written) in javascript.

    http://malsup.com/jquery/form/

    To Upload File in PHP

     500000) {
        echo "Sorry, your file is too large.";
        $uploadOk = 0;
    }
    // Allow certain file formats
    if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
    && $imageFileType != "gif" ) {
        echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
        $uploadOk = 0;
    }
    // Check if $uploadOk is set to 0 by an error
    if ($uploadOk == 0) {
        echo "Sorry, your file was not uploaded.";
    // if everything is ok, try to upload file
    } else {
        if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
            echo "The file ". basename( $_FILES["file"]["name"]). " has been uploaded.";
        } else {
            echo "Sorry, there was an error uploading your file.";
        }
    }
    ?>
    

提交回复
热议问题