以前曾在这里提出过这种类型的问题,但在这种情况下没有解决方案。我有一个用CI
开发的网站管理面板,我的目录如下。
uploads
/stores
/products
admin
/application
/system
/assets
现在,我必须通过控制器上传位于根目录中的上传子文件夹中的文件。
我四处寻找了其他解决方案,并尝试了以下方法:
$upload_path = './uploads/stores/';
当我把上传文件夹放在管理文件夹中时,上面的代码就可以工作了。但我需要将上传文件夹保存在管理员之外。
我查看了CI
使用的路径,基于此,这里是我尝试的另一种方法
$upload_path = '../../uploads/stores/';
以及
$upload_path = '/home/domain/public_html/uploads/stores/';
但这给了我以下的错误。
图像的路径不正确。
我在这里完全迷路了。欢迎提出任何建议。
您可以在上传图像时指定以下路径。
$uploadpath = $_SERVER[DOCUMENT_ROOT'].'/folderame';
直接在其下执行当前脚本的文档根,如服务器配置文件中所定义。
使用APPPATH和FCPATH生成正确的结构:
- FCPATH:包含项目的文件夹的路径
-
APPPATH:应用程序文件夹的路径
echo FCPATH .'uploads'.DIRECTORY_SEPARATOR.'stores';
if($this->input->post('img_status') == 3){//here 3 is indicating that new image is selected
if(!empty($_FILES['image']['name'])){
$name_array = '';
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|jpeg|png|bmp';
$config['max_size'] = '1000';
$config['max_width'] = '1280';
$config['max_height'] = '1280';
$this->load->library('upload');
$this->upload->initialize($config);
if(!$this->upload->do_upload('image'))
$this->upload->display_errors();
else {
$fInfo = $this->upload->data(); //uploading
$this->gallery_path = realpath(APPPATH . '../uploads');//fetching path
$config1 = array(
'source_image' => $fInfo['full_path'], //get original image
'new_image' => $this->gallery_path.'/thumb', //save as new image //need to create thumbs first
'maintain_ratio' => true,
'width' => 250,
'height' => 250
);
$this->load->library('image_lib', $config1); //load library
$this->image_lib->resize(); //generating thumb
$imagename=$fInfo['file_name'];// we will get image name here
$dataInsert['image'] = $imagename;
}
}
}
else if($this->input->post('img_status') == 2){
$dataInsert['image'] = NULL;
}
对于要向上移动的每个目录,目录处理都非常容易。//所以
试试这个,继续添加。//直到你到达你想去的地方。代码:$dir="../../gallery/safe/";