0

通常の方法でCodeIgniter2.0.2に単一のファイルをアップロードしようとしています。関数はtrueを返しますが、do_upload()ディレクトリにファイルは表示されません。ディレクトリのアクセス許可は(以下のコードに示されていない他の診断を実行した後)正常であるように見えるため、ファイルがアップロードディレクトリに表示されていないことは意味がありません。これは、CIドキュメントから直接適合させたコントローラーとビューのコードです。

コントローラ:

function do_upload_sql(){
    // create directory
    if (! is_dir(BACKUP_DIR)) {
        mkdir(BACKUP_DIR, 0777);
    }
    // or if it exists and has restricted file permissions, change them
    elseif(fileperms(BACKUP_DIR)!=0777){
        chmod(BACKUP_DIR, 0777);
    }

    $config['upload_path'] = BACKUP_DIR;
    $config['allowed_types'] = 'backup'; // an SQL backup file type
    $config['overwrite'] = TRUE;
    $this->load->library('upload', $config);
    //$this->upload->initialize($config);  //redundant, so commenting out
    if ( ! $this->upload->do_upload())
    {
        $data['action'] = 'c_backup_restore/do_upload_sql';
        $tab_error = array('error' => $this->upload->display_errors());
        $data['error'] = $tab_error['error'];
        $this->load->view('common/header');
        $this->load->view('v_upload_sql', $data);
    }
    else
    {
        echo "success"; // yes it's getting here, but i get no file!
        $data = array('upload_data' => $this->upload->data());
        $file_upload = $data["upload_data"];
        $this->restore_backup($file_upload); // go do something useful with the file
    }
}

意見:

<p>Select the backup file</p>
<div class="not_success"><?php echo $error;?></div>
<?php echo form_open_multipart($action);?>
<input type="file" name="userfile" size="30" />
<input type="submit" value="Upload" />
</form>
4

1 に答える 1

0

xDebugプロファイラーを使用してバグを見つけました。chdir(path)さらに下流のネイティブphp関数が問題であることが判明しました。@qwertzmanのCI内のパスへのリンクは、ハングアップが発生する理由を正確に判断するのに役立つ場合があります。

于 2012-05-11T17:04:04.030 に答える