【发布时间】:2019-10-17 05:24:48
【问题描述】:
我有 2 个 codeigniter 应用程序,其中一个位于根目录中,另一个位于子目录中。我正在尝试从根目录中的图像/艺术家文件夹(在主应用程序中)的子目录中的应用程序上传文件,但我得到了
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 那么问题出在哪里?
【问题讨论】:
-
错误
ERROR 404 Page Not Found: Images/artists从何而来?发布的代码都不会给您该错误,因此似乎发生的事情比您向我们展示的要多... -
在问题中添加了do_upload函数
-
您似乎在最后两个脚本中做了很多相同的事情。但是您似乎也设置了不同的上传路径。请编辑您的问题以阐明何时使用哪个代码。另外,为什么不在 foreach 循环之前创建
$config-array 并重用它,而不是在每次迭代时重新创建它? -
测试时使用的是
file_exists('../images/artists'),但设置时使用的是realpath(APPPATH . '../images/artists/')。检查它们是否相同。或者更好的是,设置$path = realpath(APPPATH . '../images/artists/');,然后使用该变量来测试文件夹是否可写,并将其用于设置上传文件夹。那你就知道你测试设置的文件夹是一样的了。
标签: php codeigniter upload