上传目标文件夹似乎不可写。 (笨) [英] The upload destination folder does not appear to be writable. (Codeigniter)
问题描述
function town_upload(){
//不要创建缩略图
$ create_thumb = false;
//创建上传路径
$ path ='./public/uploads/towns/'。 $这 - > URI->链段(3);
$ config ['upload_path'] = $ path;
$ config ['allowed_types'] ='jpg';
$ config ['max_size'] ='2048';
$ config ['max_width'] ='1024';
$ config ['max_height'] ='768';
$ config ['remove_spaces'] = TRUE;
$ config ['overwrite'] = $ this-> image_upload_overwrite;
if($ this-> input-> post('image_type')=='main_image'){
$ config ['file_name'] ='main.jpg'
$ create_thumb = true;
}
$ this-> load-> library('upload',$ config);
if(!$ this-> upload-> do_upload()){
$ this-> session-> set_flashdata('upload_error',array 'error'=> $ this-> upload-> display_errors()));
} else {
// sucess所以现在我们创建缩略图
$ this-> session-> set_flashdata('upload_success',$ this- > upload->数据());
示例:如果我有一个ID为6的城镇,上传目录将是公开/上传/城镇/ 6。当创建该城镇时,创建目录时,这样做的效果非常好。酒店几乎完全相同的功能,除了路径是公共/上传/酒店/ [ID]。我已经将权限设置为777,只是为了从现在的方程式中删除。
我无法理解这一点,因为它们都是非常相似的功能。以下是酒店上传代码:
function hotel_upload(){
//创建路径上传
$ path ='./public/uploads/hotels/'。 $这 - > URI->链段(3);
chmod($ path,0777);
$ config ['upload_path'] = $ path;
$ config ['allowed_types'] ='jpg';
$ config ['max_size'] ='2048'; //千字节(2048 = 2mb)
$ config ['max_width'] ='1024';
$ config ['max_height'] ='768';
$ config ['remove_spaces'] = TRUE;
$ config ['overwrite'] = TRUE;
if($ this-> input-> post('image_type')=='main_image'){
$ config ['file_name'] ='main.jpg'
}
$ this-> load-> library('upload',$ config);
if(!$ this-> upload-> do_upload()){
$ this-> session-> set_flashdata('upload_error',array 'error'=> $ this-> upload-> display_errors()。'< br /> Path:'。$ path。'< br />图像类型:'。$ this->输入 - >柱( 'IMAGE_TYPE')));
} else {
// sucess所以现在我们创建缩略图
$ this-> session-> set_flashdata('upload_success',$ this- > upload->数据());
酒店功能提供错误上传目的地文件夹似乎不可写入。
以下是HTML表单的页面:
TOWN:
<?php echo form_open_multipart('admin / town_upload /'。$ this-> uri-> segment(3));?>
< input type =filename =userfilesize =20/>
< br />< br />
< p>
< input type =radioname =image_typechecked =checkedclass =radiovalue =main_image/> < label>主图像< / label>
< input type =radioname =image_typeclass =radiovalue =other_image/> < label>其他图像< / label>
< / p>
< input type =submitclass =submit shortvalue =upload/>
<?php echo form_close(); ?>
酒店:
code><?php echo form_open_multipart('admin / hotel_upload /'。$ this-> uri-> segment(3));?>
< input type =filename =userfilesize =20/>
< br />< br />
< p>
< input type =radioname =image_typechecked =checkedclass =radiovalue =main_image/> < label>主图片(访问者搜索网站时显示)< / label>
< input type =radioname =image_typeclass =radiovalue =other_image/> < label>标准图像< / label>
< / p>
< input type =submitclass =submit shortvalue =upload/>
<?php echo form_close(); ?>
提前感谢!已经工作了几个小时了.. ..(
好的,刚刚回来了,我觉得权限搞砸了在某处,我销毁并重新创建了该文件夹,似乎有效。
I have two upload scripts that do very similar functions just with different directories.
function town_upload() {
//Do not create a thumbnail
$create_thumb = false;
//Create the path for the upload
$path = './public/uploads/towns/' . $this->uri->segment(3);
$config['upload_path'] = $path;
$config['allowed_types'] = 'jpg';
$config['max_size'] = '2048';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['remove_spaces'] = TRUE;
$config['overwrite'] = $this->image_upload_overwrite;
if ($this->input->post('image_type') == 'main_image') {
$config['file_name'] = 'main.jpg';
$create_thumb = true;
}
$this->load->library('upload', $config);
if (!$this->upload->do_upload()) {
$this->session->set_flashdata('upload_error', array('error' => $this->upload->display_errors()));
} else {
//sucess so now we create the thumbnail
$this->session->set_flashdata('upload_success', $this->upload->data());
Example: If I had a town with the ID of 6, the upload directory would be public/uploads/towns/6. This works perfectly fine as the directory is created when the town is created. I have nearly the exact same function for hotels except the path is public/uploads/hotels/[ID]. I have set the permissions to 777 just to remove that from the equation for now.
I cannot figure this out as they are both very similar functions. Here is the hotel upload code:
function hotel_upload() {
//Create the path for the upload
$path = './public/uploads/hotels/' . $this->uri->segment(3);
chmod($path, 0777);
$config['upload_path'] = $path;
$config['allowed_types'] = 'jpg';
$config['max_size'] = '2048'; //kilobytes (2048 = 2mb)
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['remove_spaces'] = TRUE;
$config['overwrite'] = TRUE;
if ($this->input->post('image_type') == 'main_image') {
$config['file_name'] = 'main.jpg';
}
$this->load->library('upload', $config);
if (!$this->upload->do_upload()) {
$this->session->set_flashdata('upload_error', array('error' => $this->upload->display_errors() . ' <br/>Path: ' . $path . '<br/>Image Type: ' . $this->input->post('image_type')));
} else {
//sucess so now we create the thumbnail
$this->session->set_flashdata('upload_success', $this->upload->data());
The hotel function gives me the error "The upload destination folder does not appear to be writable.".
Here are the pages HTML forms:
TOWN:
<?php echo form_open_multipart('admin/town_upload/' . $this->uri->segment(3));?>
<input type="file" name="userfile" size="20" />
<br /><br />
<p>
<input type="radio" name="image_type" checked="checked" class="radio" value="main_image" /> <label>Main Image</label>
<input type="radio" name="image_type" class="radio" value="other_image" /> <label>Other Image</label>
</p>
<input type="submit" class="submit short" value="upload" />
<?php echo form_close(); ?>
HOTEL:
<?php echo form_open_multipart('admin/hotel_upload/' . $this->uri->segment(3));?>
<input type="file" name="userfile" size="20" />
<br /><br />
<p>
<input type="radio" name="image_type" checked="checked" class="radio" value="main_image" /> <label>Main Image (shown when visitors search the website)</label>
<input type="radio" name="image_type" class="radio" value="other_image" /> <label>Standard Image</label>
</p>
<input type="submit" class="submit short" value="upload" />
<?php echo form_close(); ?>
Thanks in advance! Been working on this for hours now.. :(
Okay, just came back to this. I think permissions got messed up somewhere, I destroyed and recreated the folder and it seemed to work.
这篇关于上传目标文件夹似乎不可写。 (笨)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!