我是php CodeIgniter(3.1.4)框架的新手。现在我在一个项目工作。在我的项目中,我需要上传图片。我写了一个上传图片的方法。它在我的本地主机上完美运行。但是当我在我的网站(共享主机)中托管我的项目时,我遇到了500错误。我在下面给出了我的代码和文件结构权限。 文件权限:应用程序(0755),资产(0755),上传(0755)
代码 - > 控制器:
public function save_carousel_image() {
if (!empty($this->session->userdata('user_session'))) {
$path = '';
$new_name = $_FILES["image"]['name'];
$config['file_name'] = $new_name;
$config['upload_path'] = './assets/uploads/carousel_images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 2048;
$this->load->library('upload', $config);
$carousel_image_name = trim($this->input->post('carousel_image_name'));
if (!$this->upload->do_upload('image')) {
$error = array('error' => $this->upload->display_errors());
echo 'You did not select a file to upload.';
} else {
$carousel_image_name = trim($this->input->post('carousel_image_name'));
$data = array('upload_data' => $this->upload->data());
$path = 'assets/uploads/carousel_images/' . $data['upload_data']['file_name'];
$data = array(
'carousel_image_name' => $carousel_image_name,
'carousel_image_path' => $path
);
$this->Carousel_image_Model->db->insert('carousel_image', $data);
redirect(base_url('admin/carousel_image'));
}
} else {
redirect(base_url('admin/user_login'));
}
}
视图 - >
<div class="form-group">
<span class="btn btn-success fileinput-button">
<i class="fa fa-upload"></i>
<span>Upload File</span>
<input type="file" name="image" id="image" onchange="readURL(this)" >
</span>
</div><div class="card" style="background-color: white;">
<img id="bannerImage" src="" height="300px" width="300px">
</div><script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#bannerImage').addClass('image-preview');
$('#bannerImage').attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
}
</script>