Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Upload file error

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Upload file error

Postby furqon » Tue Feb 26, 2013 8:36 pm

agan", suhu",, numpang nanya,,
ane mw bkin form register yg ada upload filenya, smcem upload cv gtu,,
tpi pas upload filenya malah error,,
ni coding ane :
Code: Select all
<div id="content">         
        <div class="title">
         <h2>Pendaftaran Member Instruktur</h2>
        </div>
      <p align="center">Silahkan daftar dengan mengisi form dibawah ini:</p>
        <div style="border-bottom:1px solid #eee;margin: 5px 0 10px;"></div>
      <form action="register-aksi.html" method="POST" id="contactForm">
      <label for="nama">Nama</label><br/>
      <input type="text" name="nama" size="40"><br/>
      <label for="jenis">Jenis Kelamin</label><br/>
      <select name="jenis" id="jenis" >
      <option value="laki-laki">Laki-Laki</option>
      <option value="perempuan">Perempuan</option>
      </select><br />
      <label for="alamat">Alamat</label><br />
      <textarea name="alamat" style="width: 315px; height: 100px;"></textarea><br />
      <label for="notelp">No Telepon</label><br />
      <input type="text" name="notelp" size="40"><br />
      <label for="email">Email</label><br />
      <input type="text" name="email" size="40"><br />
      <label for="agama">Agama</label><br />
      <select name="agama" id="agama" >
      <option value="islam">Islam</option>
      <option value="kristen">Kristen</option>
      <option value="katolik">Katolik</option>
      <option value="hindu">Hindu</option>
      <option value="budha">Budha</option>
      </select><br />      
      <label for="data_upload">Upload CV</label><br />
      <input type="file" name="data_upload"><br />
      <img src="captcha.php"><br/>
      <label for="captcha">(Masukkan 6 kode diatas)</label><br />
      <input type="text" name="kode" size="6" maxlength="6"><br />
      <input type="submit" name="btnUpload" value="Kirim">
      </form><br />
      </div>         
<?php
// Modul register
} elseif ($_GET['module']=='registeraksi'){
?>
   <div id="content">         
        <div class="title">
         <h2>Register</h2>
        </div>
      <?php

      $nama = trim($_POST['nama']);
      $jenis = trim($_POST['jenis']);
      $alamat = trim($_POST['alamat']);
      $notelp = trim($_POST['notelp']);
      $email = trim($_POST['email']);
      $subjek = trim($_POST['agama']);
      $data_upload = trim($_POST['data_upload']);

      if(empty($nama)) {
         echo 'Anda belum mengisikan NAMA<br/>';
         $err = TRUE;
      }
      if(empty($jenis)) {
         echo 'Anda belum memilih Jenis Kelamin<br/>';
         $err = TRUE;
      }
      if(empty($alamat)) {
         echo 'Anda belum mengisikan Alamat<br/>';
         $err = TRUE;
      }
      if(empty($notelp)) {
         echo 'Anda belum mengisikan No Telepon<br/>';
         $err = TRUE;
      }
      if(empty($email)) {
         echo 'Anda belum mengisikan EMAIL<br/>';
         $err = TRUE;
      }
      if(empty($data_upload)) {
         echo 'Anda belum mengupload CV<br/>';
         $err = TRUE;
      }
      if($err) {
         echo'<a href="javascript:history.go(-1)"><b>Ulangi Lagi</b><br/>';
      } elseif(!$err) {
         if(!empty($_POST['kode'])) {
            if($_POST['kode'] == $_SESSION['captcha_session']) {
   $eror       = false;
   $folder     = './images/';
   //type file yang bisa diupload
   $file_type  = array('jpg','jpeg','png','gif','zip','doc','docx','xls','xlsx','sql');
   //tukuran maximum file yang dapat diupload
   $max_size   = 4000000; // 4MB
   if(isset($_POST['btnUpload'])){
    //Mulai memorises data
    $file_name  = $_FILES['data_upload']['name'];
    $file_size  = $_FILES['data_upload']['size'];
    //cari extensi file dengan menggunakan fungsi explode
    $explode    = explode('.',$file_name);
    $extensi    = $explode[count($explode)-1];
 
    if($file_size > $max_size){
        $eror   = true;
        $pesan .= '- Ukuran file melebihi batas maximum<br />';
    }
    //check ukuran file apakah sudah sesuai
    if($eror == true){
        echo '<div id="eror">'.$pesan.'</div>';
    }
    else{
        //mulai memproses upload file
        if(move_uploaded_file($_FILES['data_upload']['tmp_name'], $folder.$file_name)){
            //catat nama file ke database
            $catat = mysql_query('INSERT INTO register(nama, jenis, alamat, notelp, email, agama, data_upload, Folder, tanggal)
         values ( "'.$_POST['nama'].'", "'.$_POST['jenis'].'", "'.$_POST['alamat'].'", "'.$_POST['notelp'].'", "'.$_POST['email'].'", "'.$_POST['agama'].'",
         "'.$file_name.'", "'.$folder.'", "'.date('Y-m-d H:i:s').'")');
            echo '<div id="msg">Berhasil mengupload file '.$file_name.'</div>';
        } else{
            echo "Proses upload eror";
        }
    }
}


mohon bantuannya... :help:
furqon
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Feb 20, 2013 12:12 am

Re: Upload file error

Postby chrisranjana » Sun Mar 03, 2013 9:27 pm

I guess you are missing the

enctype="multipart/form-data"
chrisranjana
New php-forum User
New php-forum User
 
Posts: 9
Joined: Sun Jun 24, 2012 4:32 pm
Location: Chennai India


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.