我们正在使用 CodeIgniter 框架并有一个上传页面。我们的网站位于http://www.mysite.com/directory1/(即base_path),默认情况下图像上传到文件夹http://www.mysite.com/directory1/upload/thumb/但我们需要将我们上传的图片发送到http://www.mysite.com/directory2/upload/thumb/
我尝试修改以下行无效
'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'],
有任何想法吗?谢谢!
编辑:为了 Romain 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();
}