我有兩個上傳腳本,只用不同的目錄就可以完成類似的功能。上傳目標文件夾似乎不可寫。 (Codeigniter)
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());
示例:如果我有一個ID爲6的城鎮,上傳目錄將爲public/uploads/towns/6。這個工作完全正常,因爲該目錄是在城鎮創建時創建的。除了路徑爲public/uploads/hotels/[ID]外,我對酒店的功能幾乎完全相同。我已經將權限設置爲777,只是爲了從現在的等式中刪除該權限。
我無法弄清楚這一點,因爲它們都是非常相似的功能。這裏是酒店上傳代碼:
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());
酒店功能給我的錯誤「上傳目的地文件夾似乎不可寫」。
這裏是網頁的HTML表單:
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(); ?>
提前感謝! (
是否有必要回答該問題的所有示例代碼?我很懷疑。提供一個重現問題的簡短例子。 – cweiske 2011-04-24 19:01:53
目標目錄是否真的存在?你在哪裏創建它?兩個腳本都在同一個目錄中嗎? – 2011-04-24 19:04:33
@cweiske這就是酒店上傳腳本所需的所有代碼,因爲do_upload方法總是返回false。通過HTML表單,我提交了一個滿足所有要求的簡單圖像。 – SamV 2011-04-24 19:05:39