• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[HELP] upload

#1
[eluser]C_Line[/eluser]
i wan to upload a image

Code:
view
<input type = "file" name="file" id="file">

model
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width']  = '1024';
$config['max_height']  = '768';

$this->load->library('upload', $config);

if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());

$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());

$this->load->view('upload_success', $data);

how to do ?

#2
[eluser]InsiteFX[/eluser]
It helps if you read the CodeIgniter Users Guide

CodeIgniter Users Guide - File Uploading Class

#3
[eluser]C_Line[/eluser]
i already read it, but i don't understand, every time i submit it always display nothing

heres my code

Code:
view

<form method="post" action="<?php echo base_url(). "index.php/main/updateBarang_admin/". $kode; ?>">
<tr><td align="center" >Gambar Barang  : </td><td>&lt;input type="file" name="upd_gbr_brg"&gt;&lt;/td></tr>

controller
function updateBarang_admin($kode)
{
$this->load->model('Query_barang','',TRUE);
$data['query'] = $this->Query_barang->updateBarang($kode);
}

model
function updateBarang($kode)
{
$gambar = $this->input->post('upd_gbr_brg');
$nama = $this->input->post('upd_nm_brg');
$harga = $this->input->post('upd_hg_brg');
$stok = $this->input->post('upd_sk_brg');
$berat = $this->input->post('upd_brt_brg');
$tipe = $this->input->post('upd_tipe_brg');
$gambar = $this->input->post('upd_gbr_brg');
$status = $this->input->post('status_brg');
$config['upload_path'] = './gambar/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '2000';
$config['max_width'] = '1920';
$config['max_height'] = '1280';

// You can give video formats if you want to upload any video file.

$this->load->library('upload', $config);

if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());

// uploading failed. $error will holds the errors.
}
else
{
$data = array('upload_data' => $this->upload->data());
}
}

why it display nothing ?

#4
[eluser]InsiteFX[/eluser]
Because you are not loading a view for it.

All your upload information will be in the $data array
Code:
echo $data['full_path'];

#5
[eluser]C_Line[/eluser]
i already call it

this look like this

Code:
view
&lt;form method="post" action="&lt;?php echo base_url(). "index.php/main/updateBarang_admin/". $kode; ?&gt;"&gt;
<tr><td align="center" >Gambar Barang  : </td><td>&lt;input type="file" name="upd_gbr_brg"&gt;&lt;/td></tr>

controller
function updBarang($kode)
{
$this->load->model('Query_barang','',TRUE);
$data['query'] = $this->Query_barang->ambildata_update($kode);
$data['kode'] = $kode;

$this->load->view('home_admin');
$this->load->view("updateFormBarang_admin",$data);
}

function updateBarang_admin($kode)
{
$this->load->model('Query_barang','',TRUE);
$data['query'] = $this->Query_barang->updateBarang($kode);
}

model
function updateBarang($kode)
{
$gambar = $this->input->post('upd_gbr_brg');
$nama = $this->input->post('upd_nm_brg');
$harga = $this->input->post('upd_hg_brg');
$stok = $this->input->post('upd_sk_brg');
$berat = $this->input->post('upd_brt_brg');
$tipe = $this->input->post('upd_tipe_brg');
$gambar = $this->input->post('upd_gbr_brg');
$status = $this->input->post('status_brg');
$config['upload_path'] = './gambar/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '2000';
$config['max_width'] = '1920';
$config['max_height'] = '1280';

// You can give video formats if you want to upload any video file.

$this->load->library('upload', $config);

if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());

// uploading failed. $error will holds the errors.
}
else
{
$data = array('upload_data' => $this->upload->data());
}
}

why it display nothing and how to save the file i upload to my folder (gambar)

#6
[eluser]LuckyFella73[/eluser]
It's like InsideFX said - look here:
Code:
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());

// uploading failed. $error will holds the errors.
}
else
{
$data = array('upload_data' => $this->upload->data());
}

No matter if the uload was successful or not you just
assign the upload data to $data. You have to call a view
and diplay something like uploads data or a message like
"all fine" or "upload failed".

You better let your model return "FALSE" in case the upload failed
and return the upload data in case the upload was successful.
In your controller you call the model and call a view depending
an what your model returned.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.