0

保存ボタンをクリックする前に、特定のブロックにアップロードされた画像が表示されるように、ajax を介して画像をアップロードしようとしています。ネットで検索すると以下のコードを見つけたので試してみました。正常に動作しますが、アップロードしても画像がアップロードされません。

html

<form id="overflow_imgupload" method="post" enctype="multipart/form-data" action="">
            <input type="hidden" name="position" value="" class="position"/>
            <input type="file" name="imgupload" id="imgupload" value="Upload Image" class="span12"/>
            <a id="btn_imgupload" onclick="return ajaxFileUpload();">Upload</a>
            <a  id="closeimg" >X</a>
        </form>
">
function ajaxFileUpload(){
        $("#loading")
        .ajaxStart(function(){
                $(this).show();
        })
        .ajaxComplete(function(){
                $(this).hide();
        });
        $.ajaxFileUpload({
            url:'<?php echo site_url('doajaxfileupload') ?>',
            secureuri:false,
            fileElementId:'imgupload',
            dataType: 'html',
            success: function (data, status){

                console.log(data);
                if(typeof(data.error) != 'undefined'){
                    if(data.error != ''){
                        alert(data.error);
                    }else{
                        alert(data.msg);
                    }
                }
            },
            error: function (data, status, e){
                alert(e);
            }
        })
       return false;

    }

doajaxfileupload.php で

<?php

    class Doajaxfileupload extends CI_Controller{

        function __construct() {
            parent::__construct();
            $this->load->helper('form');
            $this->load->helper('url');
            //$this->load->library('upload');
        }

        function index(){
            $error = "";
    $msg = "";
    $fileElementName = 'imgupload';
    if(!empty($_FILES[$fileElementName]['error']))
    {
        switch($_FILES[$fileElementName]['error'])
        {

            case '1':
                $error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
                break;
            case '2':
                $error = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
                break;
            case '3':
                $error = 'The uploaded file was only partially uploaded';
                break;
            case '4':
                $error = 'No file was uploaded.';
                break;

            case '6':
                $error = 'Missing a temporary folder';
                break;
            case '7':
                $error = 'Failed to write file to disk';
                break;
            case '8':
                $error = 'File upload stopped by extension';
                break;
            case '999':
            default:
                $error = 'No error code avaiable';
        }
    }elseif(empty($_FILES[$fileElementName]['tmp_name']) || $_FILES[$fileElementName]['tmp_name'] == 'none')
    {
        $error = 'No file was uploaded..';
    }else 
    { //$msg .= $_FILES[$fileElementName]['name'];

            $config['allowed_types'] = 'jpg|png|jpeg|bmp|gif';
            $config['upload_path'] = './uploaded_files/';
            $config['max_width'] = '720';
            $config['max_height'] = '240';
            $config['min_width'] = '325';
            $config['min_height'] = '240';

            $this->load->library('upload',$config);

            if ($this->upload->do_upload($_FILES[$fileElementName]['name'])) {
                $msg .= "Upload success!";
            } else {

                $msg .= "UPoloadfailes";
            }


        }       
    echo "{";
    echo                "error: '" . $error . "',\n";
    echo                "msg: '" . $msg . "'\n";
    echo "}";
        }



    }

?>

UPoloadfailes.why?? を警告するたびに

どんな助け/提案も歓迎します。よろしくお願いします。

4

1 に答える 1