我們正在使用CodeIgniter框架並且有一個上傳頁面。我們的網站是http://www.mysite.com/directory1/(這是BASE_PATH),默認情況下的圖像上傳到該文件夾http://www.mysite.com/directory1/upload/thumb/但我們需要我們上傳的圖片發送到http://www.mysite.com/directory2/upload/thumb/在CodeIgniter中更改默認圖片上傳位置的URL
我試着修改下面一行的無影響
'new_image' => $base_path.'upload/thumb/'.$picture['file_name'],
不成功的修改:
'new_image' => $base_path.'../directory2/upload/thumb/'.$picture['file_name'],
'new_image' =>'http://www.mysite.com/directory2/upload/thumb/'.$picture['file_name'],
任何想法?謝謝!
編輯:對於羅曼Guidoux的好處,這裏是全功能:
function add_gallery($id)
{
$CI =& get_instance();
$base_path = $CI->config->slash_item('base_path');
$project_id=$this->session->userdata('project_id');
if($_FILES['file_up']['name']!='')
{
$cnt=1;
$this->load->library('upload');
$rand=rand(0,100000);
for($i=0;$i<count($_FILES['file_up']['name']);$i++)
{
if($_FILES['file_up']['name'][$i]!='')
{
$_FILES['userfile']['name'] = $_FILES['file_up'] ['name'][$i];
$_FILES['userfile']['type'] = $_FILES['file_up'] ['type'][$i];
$_FILES['userfile']['tmp_name'] = $_FILES['file_up'] ['tmp_name'][$i];
$_FILES['userfile']['error'] = $_FILES['file_up']['error'][$i];
$_FILES['userfile']['size'] = $_FILES['file_up'] ['size'][$i];
$config['file_name'] = $rand.'project_'.$i;
$config['upload_path'] = 'upload/orig/';
$config['allowed_types'] = 'jpg|jpeg|gif|png|bmp';
$this->upload->initialize($config);
if (!$this->upload->do_upload())
{
$error = $this->upload->display_errors();
}
$picture = $this->upload->data();
$this->load->library('image_lib');
$this->image_lib->clear();
$this->image_lib->initialize(array(
'image_library' => 'gd2',
'source_image' => $base_path.'upload/orig/'.$picture['file_name'],
'new_image' => $base_path.'upload/test/'.$picture['file_name'],
'maintain_ratio' => TRUE,
'quality' => '100%',
'width' => 602,
'height' => 340
));
if(!$this->image_lib->resize()){
$error = $this- >image_lib->display_errors();
}
我認爲有可能導致'HTTP的部分選項:// www.mysite.com/directory1中/ directory2 /上傳/拇指/'作爲BASE_PATH是'HTTP:// WWW .mysite.com/directory1 /'(它有一個斜線 - 我知道因爲原始的上傳文件夾upload/thumb /正常工作,但它需要位於新目錄中)。 – JoeW
你在哪裏使用這條路?它是爲了一個功能嗎?如果是這樣,看看我的編輯 –
我已經編輯了我的原始帖子與整個功能。請注意** base_path **也在目錄中。 – JoeW