Postingan lainnya
penyebab image tidak dapat di upload di codeigniter ?
permasalahanya saya tidak bisa upload gambar melalui form jadi yang di triger adalah kondisi di bawah :
if(!$this->upload->do_upload('userfile')){
// $error = array('error' => $this->upload->display_errors());
// $post_image = 'noimage.jpg';
die('gagal');
}
ini code controller saya :
public function create(){
$data['title'] = "Form Create";
$data['categories'] = $this->Post_model->get_categories();
$this->form_validation->set_rules('title','Title','required');
$this->form_validation->set_rules('body','Body','required');
if($this->form_validation->run() === FALSE){
$this->load->view('templates/header');
$this->load->view('posts/create', $data);
$this->load->view('templates/footer');
}else{
$config['upload_path'] = './assets/images/posts';
$config['allowed_types'] = 'gif|jpg|jpeg';
$config['max_size'] = 2048;
$config['max_width'] = 1000;
$config['max_height'] = 1000;
$this->load->library('upload', $config);
if(!$this->upload->do_upload('userfile')){
// $error = array('error' => $this->upload->display_errors());
// $post_image = 'noimage.jpg';
die('gagal');
}else{
$data = array('upload_data' => $this->upload->data());
$post_image = $_FILES['userfile']['name'];
}
$this->load->library('upload', $config);
$this->Post_model->create_post($post_image);
redirect('posts');
}
}
form create saya, saya tambahkan input file :
<h2 class="text-center" ><?= $title ?></h2>
<?php echo validation_errors(); ?>
<?php echo form_open_multipart('posts/create'); ?>
<div class="form-group">
<label for="">Post Title</label>
<input type="text" class="form-control" name ="title" placeholder="Post Title :">
</div>
<div class="form-group">
<label for="exampleTextarea">Body :</label>
<textarea class="form-control" id="exampleTextarea" rows="3" name="body" placeholder="Add Body :"></textarea>
</div>
<div class="form-group">
<label for="exampleSelect1">Example select</label>
<select class="form-control" name="category_id">
<?php foreach($categories as $cat) : ?>
<option value="<?= $cat['id']?>"><?= $cat['name']?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="upload Image">Upload Image</label><br>
<input type="file" name="userfile" size="20">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<?php echo form_close(); ?>
0
4 Jawaban:
Di contoh upload_path nya akhirannya kasih "/" coba
1
Dan pastikan foldernya sudah ada/sudah dipersiapkan
1
sudah saya coba gan kasi /, foldernya juga sudah ada di root nya, tabi tetep gak mau. tadi code uploadnya saya ketik ulang, entah kenapa sekarang udah bisa, btw terimakasih
0
Tanggapan
tetapi saya tidak menggunnakan form validation,
<div>Bg ivan , itu kenapa ya, saya juga mengalaminya bg, sama kaya abang, dimana salahnya ya bg??</div>
0