4

今私は読んだ修正のほとんどを試しました、それらのほとんどはAPPPATH、base_url()、実際のパスなどについて言及していますが、なぜそれらすべてが機能しなかったのか、何のために機能したのか本当にわかりません私は、URLではなく実際のパスを使用しましたが、C:\ xampp \ htdocs .. blah blah blah ..を使用しました。これで、URLとディレクトリが同じではないというスレッドを1つ読みました。 。そしてupload_pathはディレクトリパスのみを受け入れます。つまり、URLではなくサーバー上のuploadsフォルダーの実際の場所を意味します。今私の質問はAPPPATHが機能しない理由です。私が知っているのは、実際のディレクトリパスです。しかし、表示しようとすると、アップロード時に$config['upload_path']で使用される実際の最適なパスは「../applicaiton/」のみが返されます。

編集:

私はこれを別のファイルに持っています...upload.php

<?php 
$config['upload_path'] ='./uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '5000';
$config['max_width'] = '1600';
$config['max_height'] = '1200';

これが私のコントローラーです

     if($this->upload->do_upload('image'))
     {
         //Did something here
     }
     else
     {
        //Did something for errors like display_errors()
     }

最終的には、「アップロードパスが有効ではないようです」と表示され、これらのコード行も試しました。

試験1:

$config['upload_path'] ='./uploads/';

試験2:

$config['upload_path'] ='uploads/';

試験3:

$config['upload_path'] ='/admin/assets/uploads/';

試験4:

$config['upload_path'] ='./admin/assets/uploads/';

試験5:

$config['upload_path'] ='admin/assets/uploads/';

動作するのはこれだけです

 $config['upload_path'] ='C:\xampp\htdocs\practice\admin.abcgencon\admin\assets\uploads'';

最後の部分をパスとして使用するのはちょっと面倒なので、私も試しましAPPPATHたが、機能しません。「../application」も表示されます。

@crypticが言ったように、私はこのコードスニペットを投稿しました。

4

8 に答える 8

18

質問、あなたは別々に試しrealpathましたAPPPATHか?

CodeigniterではAPPPATH、アプリケーションフォルダを指します。

:(そのようにしない場合は、アプリケーションフォルダーの外にフォルダーを配置します)、imagesというファイルを配置するフォルダーを考えてみましょう。

だからあなたがする必要があるのはrealpath()とAPPPATH

$image_path = realpath(APPPATH . '../images');

そしてそれをあなたの設定に渡します

$config['upload_path'] = $image_path;
于 2013-02-24T11:47:03.330 に答える
1

アプリケーションディレクトリの外部またはCIのルートディレクトリにアップロードなどのファイルアップロードディレクトリを作成し、アップロードパスを次のように設定します。-

$config['upload_path'] = realpath(FCPATH.'uploads');

FCPATH:index.phpが存在するフロントコントローラーへのパス(CIのルート)

上記のコードは、サーバーとローカルの両方で実行されます。

于 2017-04-12T10:29:33.277 に答える
0

これは、CIでファイルのアップロードが行われる方法です

$cat_image_name = $_FILES["cat_image"]["name"] ; 

//file uploading params
$config['upload_path'] = './uploaded_files/categories';
$config['allowed_types'] = 'gif|jpg|png';
$config['file_name'] = $image_id."_ipad";
$config['remove_spaces'] = TRUE;

//Loading Library - File Uploading
$this->load->library('upload', $config);

//Upload the image(Ipad)
if (!empty($cat_image_name)) 
{
  $this->upload->do_upload('cat_image');
  $data = array('upload_data' => $this->upload->data());
  $category_image_ipad = $data['upload_data']['file_name'];
  $img_extension = $data['upload_data']['file_ext'];
}
于 2013-02-24T11:23:14.207 に答える
0

これを試して

$config['upload_path'] = '../uploads/;

それは私にとって非常にうまく機能しています

于 2016-10-19T06:52:14.393 に答える
0

これを使って:

$config['upload_path'] = $_SERVER['DOCUMENT_ROOT']."/uploads/";
//$this->config->item('upload_path');
于 2017-07-24T08:24:10.397 に答える
0

ファイルのアップロードにはマルチパートフォームが必要です。このためには、フォームヘルパーが含まれている必要があります。

configフォルダーに移動し、autoloadをクリックして、$autoload['helper'] = array();'form'を見つけて配置します。

$autoload['helper'] = array('form');

コントローラーの場合:

$ config = array(

    'upload_path' => "./assets/",
    'allowed_types' => "gif|jpg|png|jpeg",
    'overwrite' => TRUE,
    'max_size' => "2048000",
    'max_height' => "768",
    'max_width' => "1024"
    );

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

    if(!$this->upload->do_upload()){
        $errors = array('error' => $this->upload->display_errors());
        $post_image = 'noimage.jpg';
    } else {
        $data = array('upload_data' => $this->upload->data());
        $post_image = $_FILES['userfile']['name'];
    }

    $this->user_model->create_photo($post_image);
    redirect('');
}

モデルの場合:

public function create_photo($post_image){

    $data = array(
        'pri' => $this->input->post('price'),
        'descrip' => $this->input->post('title'),
        'post_image' => $post_image
    );

    return $this->db->insert('table_name', $data);
}
于 2018-05-17T07:49:22.870 に答える
0

WindowsとLinuxでテスト済み:

$path = realpath(".");
$path .= "/uploads/profile_images";

ここでuploadsはrootのuploadsディレクトリです。

于 2018-05-30T15:19:36.360 に答える
-1

それは非常に簡単です:

すべての$configをupload.phpという新しいphpファイルにコピーして、cofigフォルダーに配置するだけです。

パスは問題なく機能します。

upload.phpファイルの内容は次のとおりです。

<?php

    $config['upload_path'] = site_url().'uploads';
    $config['allowed_types'] = 'gif|jpg|png|jpeg|html|pdf';
    $config['max_size'] = 0;
    $config['max_width']  = 0;
    $config['max_height']  = 0;
    $config['file_ext_tolower']  = TRUE;
    $config['overwrite']  = FALSE;
    $config['max_filename']  = 0;
    $config['encrypt_name']  = TRUE;
    $config['remove_spaces']  = TRUE;
    $config['detect_mime']  = TRUE;
    $config['mod_mime_fix']  = TRUE;
?>

ただし、upload_fileコントローラーにも$ configデータを保持してください。例:

public function do_upload(){

    $config['upload_path'] = 'uploads';
    $config['allowed_types'] = 'gif|jpg|png|jpeg|html|pdf';
    $config['max_size'] = 0;
    $config['max_width']  = 0;
    $config['max_height']  = 0;
    $config['file_ext_tolower']  = TRUE;
    $config['overwrite']  = FALSE;
    $config['max_filename']  = 0;
    $config['encrypt_name']  = TRUE;
    $config['remove_spaces']  = TRUE;
    $config['detect_mime']  = TRUE;
    $config['mod_mime_fix']  = TRUE;

//Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:

   $this->upload->initialize($config);


            if (!$this->upload->do_upload('userfile'))
    {
        $error = array('error' => $this->upload->display_errors());

        $this->load->view('upload_form', $error);
    }
    else
    {
        $data = array('upload_data' => $this->upload->data());

        $this->load->view('upload_success', $data);
    }
    }

簡単です...

于 2015-12-29T06:20:32.320 に答える