Skip to main content

script upload file (file-nya bertipe dokumen az)

July 29, 2009 by cah_ajus

cah_ajus's picture

ad yg punya script bwt upload ngk..,????
tlong donk...,!!please....,
sdh sempet gogling tuk nyari2..,dpt link dbwh ni :

http://dhenick.web.id/?p=24#more-24
http://kohaci.com/2008/12/14/image-resizing-di-php-codeigniter.html
tapi msh lum ngerti jg...,^_^

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

upload file

July 30, 2009 by eien, 2 years 2 weeks ago
Comment: 5592

eien's picture

pertama-tama bikin view dengan isi sebagai berikut :

<?php
//jangan lupa menyertakan $this->load->helper('form'); di controller yang memanggil view ini 
echo form_open_multipart('upload_file/cobaupload', '').
         form_upload('myfile').
         form_submit('submit', 'Submit').'</p>';
?>

lalu di controller upload_file.php seperti demikian :

function cobaupload(){
     $config['upload_path'] = './userfiles/'; //pastikan permissionnya udah diset ke 777
     $config['allowed_types'] = 'az';//tipe file yang diperbolehkan
     $this->load->library('upload', $config);
     if($this->upload->do_upload('myfile')){//jika file berhasil diupload
          $tp=$this->upload->data();
         echo $tp['file_name'].'berhasil di-upload';
     }else//jika gagal
          echo $this->upload->display_errors();
}

gak ngerti

June 7, 2011 by hery_yud, 10 weeks 7 hours ago
Comment: 8313

hery_yud's picture

$config['upload_path'] = './userfiles/'; //pastikan permissionnya udah diset ke 777

maksud dr nih apa ya. diset ke 777

caranya nge-setnya gmn?

oke

July 30, 2009 by cah_ajus, 2 years 2 weeks ago
Comment: 5593

cah_ajus's picture

matur nuhun mas....,!!sudah bisa saia jalankan..,

insert to database

July 30, 2009 by cah_ajus, 2 years 2 weeks ago
Comment: 5597

cah_ajus's picture

gmn kalau pngen data yg diupload masuk k dlm database.,???
trus., gmn caranya bwt halaman downloadnya..,???
thanx's b4

simpan file

July 31, 2009 by eien, 2 years 2 weeks ago
Comment: 5598

eien's picture

untuk data yang diupload masuk ke dalam database sebenarnya cukup disimpan link-nya aja di dalam database, jadi melanjuti script sebelumnya

function cobaupload(){
     $config['upload_path'] = './userfiles/'; //pastikan permissionnya udah diset ke 777
     $config['allowed_types'] = 'az';//tipe file yang diperbolehkan
     $this->load->library('upload', $config);
     if($this->upload->do_upload('myfile')){//jika file berhasil diupload
          $tp=$this->upload->data();
         echo $tp['file_name'].'berhasil di-upload';
         $data = array( 
                      'path_file' => 'userfiles/'.$tp['file_name'] //cukup dimasukkan link-nya saja
	  );
	  $this->db->insert('namatabel', $data);  //masukkan tabelnya
     }else//jika gagal
          echo $this->upload->display_errors();
}

untuk halaman downloadnya bisa menggunakan download helper-nya code igniter, klo secara simpelnya seperti ini :

function testdownload(){
		$this->load->helper('download');
		$data = file_get_contents("userfiles/contoh.az"); 
		$name = 'fileku.az'; //nama file yang akan diterima user
 
		force_download($name, $data); 
	}

ketika controller diatas diakses otomatis akan mendownload file pada path userfiles/contoh.az sebagai fileku.az

error

July 31, 2009 by cah_ajus, 2 years 2 weeks ago
Comment: 5599

cah_ajus's picture

koq error yach..,???
kykna tipe data untuk nyimpan di database ku salah..,aq setting varchar (50)...,salah yach..,???

$this->db->insert('namatabel', $data);// ini nama tabel, trus nama kolomnya ngk perlu..,???misalnya tabelnya ada banyak kolom gtu???

error codenya ?

August 1, 2009 by eien, 2 years 2 weeks ago
Comment: 5600

eien's picture

errornya tulisannya apa yah ?

gak kok, varchar(50) seharusnya cukup asal nama file gak terlalu panjang.

$data = array( 
                      <strong>'path_file'</strong> => 'userfiles/'.$tp['file_name'] //cukup dimasukkan link-nya saja
      );
      $this->db->insert('namatabel', $data);  //masukkan tabelnya

yang 'path_file' itu nama kolomnya, klo banyak kolom tinggal diubah seperti ini :

$data = array( 
                      'path_file' => 'userfiles/'.$tp['file_name'],
                     'kolom_2' => 'apapun',
                     'kolom_3' => 'apapun'
      );
      $this->db->insert('namatabel', $data);  //masukkan tabelnya

terima ksih

August 2, 2009 by cah_ajus, 2 years 1 week ago
Comment: 5601

cah_ajus's picture

tengkyu2.....sudah bisa saia jalankan...,
sungguh sangat membantu...,'
^_^

tanya ttg download

August 4, 2009 by cah_ajus, 2 years 1 week ago
Comment: 5604

cah_ajus's picture

sorie sebelumnya ne...,saiamo nanya2 lagi...,heheee
saia sdh berhasil menjalankan script upload-ny dan link-ny sudah tersimpan di database.
skr saia mo tanya ttg download...,itu script download di atas, kan download satu file.,???gimana kalau di database ada banyak link download tersimpan...,apakah ttap mke script di atas..,???
tolong bantuannya lagi yach..,

cuma bisa upload file image :-??

November 10, 2009 by kakap, 1 year 39 weeks ago
Comment: 5701

kakap's picture

btw ini scriptQ

function addFile(){
		if ($_FILES){
			$config['upload_path'] = './files/';
			$config['allowed_types'] = 'jpg|xls|png|bmp|gif|doc|rtf|txt|zip|rar|pdf|ppt';
			$config['max_size'] = '20000';
			$config['remove_spaces'] = true;
			$config['overwrite'] = false;
 
			$this->load->library('upload', $config);
 
			if (strlen($_FILES['file']['name'])){
				if (!$this->upload->do_upload('file')){
					$this->upload->display_errors();
					exit();
				}
				$file = $this->upload->data();
 
				$data = array(
				'name' => $_POST['name'],
				'date' => $_POST['date'],
				'status' => $_POST['status'],
				'size' => $file['file_size'],
				'file' => 'files/'.$file['file_name']
				);
 
				$this->db->insert('download', $data);
			}
		}
	}

aq meletakkannya pada model

dari script itu, hanya dapat upload file gambar spt jpg,gif,png. tapi kalo dipake upload ekstensi laen, doc,pdf,xls,dan laennya, GAGAL.
why???
mohon pencerahannya T_T

terimakasih

Premium Drupal Themes by Adaptivethemes