我有2个codeigniter应用程序,其中一个在根目录中,另一个在子目录中。我正在尝试从子目录中的根目录(在主应用程序中)的images / artist文件夹中的应用程序上载文件,但是我得到了
ERROR 404 Page Not Found: Images/artists
The upload destination folder does not appear to be writable.
我在用于上载子目录应用程序的控制器中运行此代码
if (file_exists('../images/artists')) {
echo 'directory exists - ';
if (!is_dir('../images/artists')) {
echo 'not a dir';
}
else{
echo 'it is a dir';
}
}
我得到“目录存在-它是一个目录”,然后运行上载代码
$gallery_path = realpath(APPPATH . '../images/artists/');
$config['upload_path'] = $gallery_path;
$config['allowed_types'] = 'jpg|png|jpeg';
$config['max_size'] = '20000';
$config['file_name'] = round(microtime(true) * 1000).'.jpg';
$this->load->library('upload', $config);
if ($this->upload->do_upload('img')) {
$phot_data = $this->upload->data();
$photo_name = $phot_data['file_name'];
$this->resizeImage($photo_name);
$artist_data['image'] = $config['file_name'];
}
//在这里没有用,但是它会覆盖并触发错误吗?
function do_upload() {
if ($_FILES['photos']['name'][0] != '') {
$name_array = array();
foreach ($_FILES as $key => $value)
$_FILES['userfile']['name'] = $value['name'];
$_FILES['userfile']['type'] = $value['type'];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'];
$_FILES['userfile']['error'] = $value['error'];
$_FILES['userfile']['size'] = $value['size'];
$config['upload_path'] = realpath(APPPATH . 'images/artists/');
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '2000';
$this->load->library('upload');
$this->upload->initialize($config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name'];
}
redirect('admin/gallery');
}
我检查了图像和艺术家权限,并将它们设置为777,那么问题出在哪里?
答案 0 :(得分:0)
第一个代码段仅检查目录是否存在,但是您想确认该目录是否可写(即可以将新文件放入其中)。
查看is_writable了解更多详细信息。要解决此问题,您需要在服务器上运行chmod 600 /path/to/images/artists
。