Forum Sementara Putera.com

Bersama kita perkemaskan forum ini sementara forum asal dalam pemulihan.

Forum putera dah kembali. Masalah sudah berjaya diselesaikan. Sila lawati http://forum.putera.com/tanya


    bagaimana nak buat function utk upload file (doc,pdf,jpg,dsb...)dalam php?

    Share

    fifi85
    Ahli Baharu
    Ahli Baharu

    Number of posts : 40
    Registration date : 03/09/2009

    bagaimana nak buat function utk upload file (doc,pdf,jpg,dsb...)dalam php?

    Post by fifi85 on Thu Oct 08, 2009 1:45 pm

    mintak tlg sapa yang tau buat..

    johnburn
    Moderators
    Moderators

    Gender : Male Number of posts : 755
    Location : Terengganu
    Registration date : 07/03/2009

    Re: bagaimana nak buat function utk upload file (doc,pdf,jpg,dsb...)dalam php?

    Post by johnburn on Thu Oct 08, 2009 2:02 pm

    xnk limit ke format yg bleh upload?


    --------------------------------------------

    tahukah kamu saat kamu menangis
    adalah air mata ku yang jatuh berlinang
    tahukah kamu saat kamu tersakiti
    adalah aku yang pertama terluka
    Jangan Klik

    fifi85
    Ahli Baharu
    Ahli Baharu

    Number of posts : 40
    Registration date : 03/09/2009

    Re: bagaimana nak buat function utk upload file (doc,pdf,jpg,dsb...)dalam php?

    Post by fifi85 on Thu Oct 08, 2009 3:16 pm

    tak perlu kot
    boleh upload sume.

    johnburn
    Moderators
    Moderators

    Gender : Male Number of posts : 755
    Location : Terengganu
    Registration date : 07/03/2009

    Re: bagaimana nak buat function utk upload file (doc,pdf,jpg,dsb...)dalam php?

    Post by johnburn on Thu Oct 08, 2009 3:57 pm

    Buat form untuk upload:
    Code:

    <form name="upload" action="upload.php" method="POST" ENCTYPE="multipart/formdata">
    Pilih fail untuk muat naik: <input type="file" name="namafail">
    <input type="submit" name="upload" value="Upload">
    </form>

    untuk upload.php bleh buat cmni:
    Code:

    <?php
    $folderUp = 'uploads/'; // nama folder untuk simpan file yg di upload
    $uploadfile = $folderUp . basename($_FILES['namafail']['name']);
    if (move_uploaded_file($_FILES['namafail']['tmp_name'], $uploadfile)) {
    echo "Fail berjaya dimuat naik.\n";
    } else {
    echo "Muat naik gagal.\n";
    }
    ?>
    Ni merupakan code asas nk buat file upload. dlm code ni kte xde cek file type atau pe2, so sgt tak x slmt untuk digunakan sbb org bleh upload shell ke ape. sekuriti mmg xde, tp untuk pham konsep file upload bleh la.


    --------------------------------------------

    tahukah kamu saat kamu menangis
    adalah air mata ku yang jatuh berlinang
    tahukah kamu saat kamu tersakiti
    adalah aku yang pertama terluka
    Jangan Klik

    fifi85
    Ahli Baharu
    Ahli Baharu

    Number of posts : 40
    Registration date : 03/09/2009

    Re: bagaimana nak buat function utk upload file (doc,pdf,jpg,dsb...)dalam php?

    Post by fifi85 on Thu Oct 08, 2009 4:04 pm

    ooo...kalau yang lebih secure bgimana plak?
    mmm kene buat form baru ke? kalau guna form yang sama xleh ke? cuma function tu pd button dia je.
    form saya tu action dia dah ke insert statement

    johnburn
    Moderators
    Moderators

    Gender : Male Number of posts : 755
    Location : Terengganu
    Registration date : 07/03/2009

    Re: bagaimana nak buat function utk upload file (doc,pdf,jpg,dsb...)dalam php?

    Post by johnburn on Thu Oct 08, 2009 4:14 pm

    actually bleh je nk ltk skali ngan form yg dh ade
    part untuk processing form tu pn bleh je gabung skali
    tu just nk tunjuk je yg asas dia
    kl nk senang, cam bese kne tunjuk code yg dh ade hehe
    tunjuk code form tu dan code yg proses form tu


    --------------------------------------------

    tahukah kamu saat kamu menangis
    adalah air mata ku yang jatuh berlinang
    tahukah kamu saat kamu tersakiti
    adalah aku yang pertama terluka
    Jangan Klik

    fifi85
    Ahli Baharu
    Ahli Baharu

    Number of posts : 40
    Registration date : 03/09/2009

    Re: bagaimana nak buat function utk upload file (doc,pdf,jpg,dsb...)dalam php?

    Post by fifi85 on Thu Oct 08, 2009 4:42 pm

    form nye panjang sket

    Code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>:: Sistem Kawalan Aduan ::</title>
    <style type="text/css">
    <!--
    .style2 {font-weight: bold}
    .style4 {font-size: 14px}
    .style5 {font-size: 18px}
    .style7 {font-size: 14px; font-weight: bold; }
    .style8 {font-size: 20px}
    .style9 {font-size: 12px}
    -->
    </style>
    </head>
    <script language="JavaScript" src="popcalendar.js"></script>
    <script language="JavaScript" src="ew.js"></script>
    <script language="JavaScript" src="ajax2.js"></script>

    <body>
    <?php
          
          include('include/connectDB.php');
          include('include/database-control.func.php');
          
    ?>             
     <form name=MyForm method="post" action="form1add.php">
     <table align="center" border="0">
      <tr>
        <td><?php include('header.php');?>
        </td>
      </tr>
     </table>
     <table width="760" border=0 align="center" cellpadding=8 cellspacing=2 bgcolor="#999999">
     <tr>
      <td colspan="2"><table width="742" border=0 cellpadding=0 cellspacing=0 bgcolor=#ffffff>
          <tr >
            <td colspan=2>&nbsp;</td>
          </tr>
          <tr>
            <td width="22%" rowspan="2" valign="middle"><div align="center"><img src="image/jpn.jpg" width="82" height="82"/><br>
              &nbsp;</div></td>
            <td width="78%" valign=top ><div align="center"><span class="style8"><strong> JABATAN PENDAFTARAN NEGARA <br>
              MALAYSIA</strong></span></div>
                <hr /></td>
          </tr>
          <tr >
            <td colspan=2><div align="center"><span class="style8">Sistem Kawalan Aduan</span><br />
                    <span class="style7">Kemasukan Aduan Baru </span></div>
                <br /></td>
          </tr>
      </table></td>
     </tr>
     <tr>
      <td width="184" bgcolor="#CCCCCC" valign="top"><?php include('menu_user.php'); ?>
    </td>
    <td width="540" bgcolor="#CCCCCC"><span class="style2"><strong>&nbsp;A. Maklumat Pengadu :</strong></span>
        <table width="540" border=0 cellpadding=8 cellspacing=2>
          <tr bgcolor=#efefef>
            <td width="146"><span class="style4">Jenis</span></td>
                <td width="356"><select name=ska_pengadu_codeJenisId id=ska_pengadu_codeJenisId>
          <option>- Sila Pilih -</option>
          <?php
    // connect ke db
    $q=mysql_query("select distinct * from data_jenisid order by jenisId ");
    while($data=mysql_fetch_array($q))
    {
    echo "<option value='$data[codeJenisId]'>$data[jenisId]</option>";
    }
    ?></select></td>
          </tr>
          <tr bgcolor=#efefef>
            <td width="146"><span class="style4">No. Kad Pengenalan / Pasport<span
              style="COLOR: #ff0000; FONT-STYLE: italic; font-weight: normal;"><sup>*</sup></span></span></td>
            <td width="356"><input name=ska_pengadu_userId id=ska_pengadu_userId size=40></td>
          </tr>
          <tr bgcolor=#efefef>
            <td bgcolor="#efefef"><span class="style4">Nama</span></td>
            <td><input name=ska_pengadu_nama id=ska_pengadu_nama size=40></td>
          </tr>
          <tr bgcolor=#efefef>
            <td valign=top><span class="style4">Alamat</span></td>
            <td><span class="style4">
              <input id=ska_pengadu_alamat1 size=40 name=ska_pengadu_alamat1>
              <br>
              <input id=ska_pengadu_alamat2 size=40 name=ska_pengadu_alamat2>
            </span></td>
          </tr>
          <tr bgcolor=#efefef>
            <td><span class="style4">Poskod</span></td>
            <td><input name=ska_pengadu_poskod id=ska_pengadu_poskod size=40></td>
          </tr>
         <tr bgcolor=#efefef>
            <td><span class="style4">Daerah</span></td>
            <td><input name=ska_pengadu_daerah id=ska_pengadu_daerah size=40></td>
          </tr>
          <tr bgcolor=#efefef>
            <td><span class="style4">Negeri</span></td>
                <td><select name=ska_pengadu_codeNegeri id=ska_pengadu_codeNegeri>
          <option>- Sila Pilih -</option>
          <?php
    // connect ke db
    $q=mysql_query("select distinct * from data_negeri order by negeri ");
    while($data=mysql_fetch_array($q))
    {
    echo "<option value='$data[codeNegeri]'>$data[negeri]</option>";
    }
    ?></select></td>
          </tr>
          <tr bgcolor=#efefef>
            <td><span class="style4">No.Telefon</span></td>
            <td><span class="style4">(R)</span>
                <input name=ska_pengadu_telRumah id=ska_pengadu_telRumah size=10>
              &nbsp;<span class="style4">(P)</span>
              <input name=ska_pengadu_telPej id=ska_pengadu_telPej size=10>
              &nbsp;<span class="style4">(H/p)</span>
              <input name=ska_pengadu_hphone id=ska_pengadu_hphone size=10></td>
          </tr>
          <tr bgcolor=#efefef>
            <td><span class="style4">Emel</span></td>
            <td><input name=ska_pengadu_emel id=ska_pengadu_emel size=40></td>
          </tr>
        </table>
      <br />
      <span class="style2"><strong>&nbsp;B. Maklumat Aduan :</strong></span>
      <table width="540" border=0 cellpadding=8 cellspacing=2>
        <tr bgcolor=#efefef>
          <td width="146"><span class="style4">Tarikh Aduan Diterima</span></td>
          <td width="356"><input name=ska_adu_dateAduan id=ska_adu_dateAduan size=40>
            &nbsp;&nbsp;
            <input name="image23" type="image" onclick="popUpCalendar(this, this.form.ska_adu_dateAduan,'yyyy-mm-dd');return false;" src="image/calendar.gif" alt="kalendar" /></td>
        </tr>
        <tr bgcolor=#efefef>
          <td><span class="style4">Sumber Aduan</span></td>
                <td><select name=ska_adu_codeSumber id=ska_adu_codeSumber>
          <option>- Sila Pilih -</option>
          <?php
    // connect ke db
    $q=mysql_query("select distinct * from data_sumber order by sumber ");
    while($data=mysql_fetch_array($q))
    {
    echo "<option value='$data[codeSumber]'>$data[sumber]</option>";
    }
    ?></select></td>
        </tr>
        <tr bgcolor=#efefef>
          <td valign=top><span class="style4">Fail Rujukan</span></td>
          <td><input id=ska_adu_noFail size=40 name=ska_adu_noFail /></td>
        </tr>
       <tr bgcolor=#efefef>
          <td><span class="style4">Negeri</span></td>
          <td>
          <select name="ska_adu_codeNegeri" id="ska_adu_codeNegeri" onchange="cawangan(this.value)">                 
    <?php       
    $query = @mysql_query("SELECT * FROM data_negeri order by negeri");       
    if (mysql_num_rows($query) > 0) {           
    echo '<option value="">- Sila Pilih -</option>';           
    while($row = mysql_fetch_array($query)) {           
    echo "<option value='".$row['codeNegeri']."'>".$row['negeri']."</option><br />";           
    }       
    }       
    ?>       
    </select></td>
        </tr>
        <tr bgcolor=#efefef>
          <td><span class="style4">Cawangan</span></td>
          <td>
          <p id="ska_adu_codeCawangan">
          <select name="ska_adu_codeCawangan">       
    <option>- Sila Pilih -</option>       
    </select></td>
        </tr>
        <tr bgcolor=#efefef>
          <td><span class="style4">Bahagian</span></td>
                <td><select name=ska_adu_codeBhgn id=ska_adu_codeBhgn>
          <option>- Sila Pilih -</option>
          <?php
    // connect ke db
    $q=mysql_query("select distinct * from data_bhgn order by bhgn ");
    while($data=mysql_fetch_array($q))
    {
    echo "<option value='$data[codeBhgn]'>$data[bhgn]</option>";
    }
    ?></select></td>
        </tr>
        <tr bgcolor=#efefef>
          <td><span class="style4">Butiran Aduan</span></td>
          <td><span class="style4">
            <textarea name=ska_adu_butiran id=ska_adu_butiran cols="40" rows="10"></textarea>
          </span></td>
        </tr>
        <tr bgcolor=#efefef>
          <td><span class="style4">Lampiran</span></td>
          <td><input type=file name=ska_adu_doc id=ska_adu_doc size=40 value=Browse></td>
        </tr>
       <tr bgcolor=#efefef>
          <td class="style4">Tarikh Aduan<br />
              <span class="style9">(Dilaporkan ke PRO)</span></td>
          <td width="356"><input name=ska_reply_datekePRO id=ska_reply_datekePRO size=40>
            &nbsp;&nbsp;
            <input name="image22" type="image" onclick="popUpCalendar(this, this.form.ska_reply_datekePRO,'yyyy-mm-dd');return false;" src="image/calendar.gif" alt="kalendar" /></td>
       </tr>
      </table>
      <br />
      <span class="style2"><strong>&nbsp;C. Status :</strong></span>
      <table width="540" border=0 cellpadding=8 cellspacing=2>
      <tr bgcolor=#efefef>
          <td class="style4">Tarikh Aduan<br />
              <span class="style9">(Selesai Dilaporkan ke PRO)</span></td>
          <td><input name=ska_reply_dateSelesaiPRO id=ska_reply_dateSelesaiPRO size=40>
            &nbsp;&nbsp;
            <input name="image2" type="image" onclick="popUpCalendar(this, this.form.ska_reply_dateSelesaiPRO,'yyyy-mm-dd');return false;" src="image/calendar.gif" alt="kalendar" /></td>
        </tr>
        <tr bgcolor=#efefef>
          <td width="146"><span class="style4">Status</span></td>
                <td width="356"><select name=ska_reply_codeStatus id=ska_reply_codeStatus>
          <?php
    // connect ke db
    $q=mysql_query("select distinct * from ska_data_status order by status ");
    while($data=mysql_fetch_array($q))
    {
    echo "<option value='$data[codeStatus]'>$data[status]</option>";
    }
    ?></select></td>
        </tr>
       <tr bgcolor=#efefef>
          <td width="146"><span class="style4">Tarikh Selesai </span></td>
          <td width="356"><input name=ska_reply_dateSelesai id=ska_reply_dateSelesai size=40>
            &nbsp;&nbsp;
            <input name="image2" type="image" onclick="popUpCalendar(this, this.form.ska_reply_dateSelesai,'yyyy-mm-dd');return false;" src="image/calendar.gif" alt="kalendar" /></td>
        </tr>
      </table>
      <br />
      <span class="style2"><strong>D. Maklumbalas / Tindakan :</strong></span>
      <table width="540" border=0 cellpadding=8 cellspacing=2>
        <tr bgcolor=#efefef>
          <td width="146"><span class="style4">Nama Pegawai</span></td>
          <td width="356"><input name=ska_reply_personIncharge id=ska_reply_personIncharge size=40></td>
        </tr>
        <tr bgcolor=#efefef>
          <td><span class="style4">Tarikh Tindakan Diambil</span></td>
          <td><input name=ska_reply_dateAct id=ska_reply_dateAct size=40>
            &nbsp;&nbsp;
            <input name="image" type="image" onClick="popUpCalendar(this, this.form.ska_reply_dateAct,'yyyy-mm-dd');return false;" src="image/calendar.gif" alt="kalendar" /></td>
        </tr>
        <tr bgcolor=#efefef>
          <td><span class="style4">Tindakan / Maklumbalas Yang Diambil</span></td>
          <td><textarea name=ska_reply_maklumBalas id=ska_reply_maklumBalas cols=40 rows="10">&nbsp;</textarea></td>
        </tr>
        <tr bgcolor=#efefef>
          <td><span class="style4">Lampiran</span></td>
          <td><input type=file name=ska_reply_doc id=ska_reply_doc size=40 value=Browse></td>
        </tr>
      </table>
      <div align="center"><br />
          <input name="Reset" type="reset" value="Kosongkan" />
        &nbsp;&nbsp;
        <input type="button" name="simpan" value="Simpan Draf" />
        &nbsp;&nbsp;
        <input name="submit" type="submit" value="Hantar" />
      </div></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    form proses (form1add.php)

    Code:

    <?php session_start(); ?>
    <?php
    include('include/connectDB.php');
    include('include/database-control.func.php');

    $_SESSION['ska_pengadu_codeJenisId']=$_POST['ska_pengadu_codeJenisId'];
    $_SESSION['ska_pengadu_userId']=$_POST['ska_pengadu_userId'];
    $_SESSION['ska_pengadu_nama']=$_POST['ska_pengadu_nama'];
    $_SESSION['ska_pengadu_alamat1']=$_POST['ska_pengadu_alamat1'];
    $_SESSION['ska_pengadu_alamat2']=$_POST['ska_pengadu_alamat2'];
    $_SESSION['ska_pengadu_poskod']=$_POST['ska_pengadu_poskod'];
    $_SESSION['ska_pengadu_daerah']=$_POST['ska_pengadu_daerah'];
    $_SESSION['ska_pengadu_codeNegeri']=$_POST['ska_pengadu_codeNegeri'];
    $_SESSION['ska_pengadu_telRumah']=$_POST['ska_pengadu_telRumah'];
    $_SESSION['ska_pengadu_telPej']=$_POST['ska_pengadu_telPej'];
    $_SESSION['ska_pengadu_hphone']=$_POST['ska_pengadu_hphone'];
    $_SESSION['ska_pengadu_emel']=$_POST['ska_pengadu_emel'];
    $_SESSION['ska_adu_dateAduan']=$_POST['ska_adu_dateAduan'];
    $_SESSION['ska_adu_codeSumber']=$_POST['ska_adu_codeSumber'];
    $_SESSION['ska_adu_noFail']=$_POST['ska_adu_noFail'];
    $_SESSION['ska_adu_codeCawangan']=$_POST['ska_adu_codeCawangan'];
    $_SESSION['ska_adu_codeNegeri']=$_POST['ska_adu_codeNegeri'];
    $_SESSION['ska_adu_codeBhgn']=$_POST['ska_adu_codeBhgn'];
    $_SESSION['ska_adu_butiran']=$_POST['ska_adu_butiran'];
    $_SESSION['ska_adu_doc']=$_POST['ska_adu_doc'];
    $_SESSION['ska_reply_datekePRO']=$_POST['ska_reply_datekePRO'];
    $_SESSION['ska_reply_dateSelesaiPRO']=$_POST['ska_reply_dateSelesaiPRO'];
    $_SESSION['ska_reply_codeStatus']=$_POST['ska_reply_codeStatus'];
    $_SESSION['ska_reply_dateSelesai']=$_POST['ska_reply_dateSelesai'];
    $_SESSION['ska_reply_personIncharge']=$_POST['ska_reply_personIncharge'];
    $_SESSION['ska_reply_dateAct']=$_POST['ska_reply_dateAct'];
    $_SESSION['ska_reply_maklumBalas']=$_POST['ska_reply_maklumBalas'];
    $_SESSION['ska_reply_doc']=$_POST['ska_reply_doc'];

    $desc = 'A';
    $tahun = date('Y');
    $sqlquery = "SELECT * FROM tbl_id WHERE code_klasifikasi='".$desc."' ORDER BY id DESC LIMIT 1"; 
    $sqlresult = mysql_query($sqlquery) or die (mysql_error());     
    $row = mysql_fetch_array($sqlresult); 
    $bil = $row['bil'] + 1;     
    $sqlquery2 = "INSERT INTO tbl_id (code_klasifikasi, tahun, bil) VALUES ('$desc', '$tahun', $bil)"; 
    $sqlresult2 = mysql_query($sqlquery2) or die (mysql_error()); 

    $sql = "INSERT INTO ska_pengadu(ska_pengadu_codeJenisId, ska_pengadu_userId, ska_pengadu_nama, ska_pengadu_alamat1, ska_pengadu_alamat2, ska_pengadu_poskod, ska_pengadu_daerah, ska_pengadu_codeNegeri, ska_pengadu_telRumah, ska_pengadu_telPej, ska_pengadu_hphone, ska_pengadu_emel, ska_pengadu_dateCreate)

    VALUES('".$_SESSION['ska_pengadu_codeJenisId']."', '".$_SESSION['ska_pengadu_userId']."', '".$_SESSION['ska_pengadu_nama']."', '".$_SESSION['ska_pengadu_alamat1']."', '".$_SESSION['ska_pengadu_alamat2']."', '".$_SESSION['ska_pengadu_poskod']."', '".$_SESSION['ska_pengadu_daerah']."', '".$_SESSION['ska_pengadu_codeNegeri']."', '".$_SESSION['ska_pengadu_telRumah']."', '".$_SESSION['ska_pengadu_telPej']."', '".$_SESSION['ska_pengadu_hphone']."', '".$_SESSION['ska_pengadu_emel']."', now())";

    $result=sqlrun($sql);

    $sql = "INSERT INTO ska_aduan(ska_adu_noAdu, ska_adu_UserId, ska_adu_codeKlasifikasi, ska_adu_codeSumber, ska_adu_dateAduan, ska_adu_noFail, ska_adu_butiran, ska_adu_doc, ska_adu_adm_id, ska_adu_dateCreate)

    VALUES('$desc/$tahun/$bil', '".$_SESSION['ska_pengadu_userId']."', 'A', '".$_SESSION['ska_adu_codeSumber']."', '".$_SESSION['ska_adu_dateAduan']."', '".$_SESSION['ska_adu_noFail']."', '".$_SESSION['ska_adu_butiran']."', '".$_SESSION['ska_adu_doc']."', '0', now())";

    $result=sqlrun($sql);

    $sql = "INSERT INTO ska_reply(ska_reply_noAdu, ska_reply_userId, ska_reply_doc, ska_reply_codeStatus, ska_reply_datekePRO, ska_reply_personIncharge, ska_reply_codeBhgn, ska_reply_dateAct, ska_reply_maklumBalas, ska_reply_dateSelesai, ska_reply_dateSelesaiPRO, ska_reply_dateCreate)

    VALUES('$desc/$tahun/$bil', '".$_SESSION['ska_pengadu_userId']."', '".$_SESSION['ska_reply_doc']."', '".$_SESSION['ska_reply_codeStatus']."', '".$_SESSION['ska_reply_datekePRO']."', '".$_SESSION['ska_reply_personIncharge']."', '".$_SESSION['ska_adu_codeBhgn']."', '".$_SESSION['ska_reply_dateAct']."', '".$_SESSION['ska_reply_maklumBalas']."', '".$_SESSION['ska_reply_dateSelesai']."', '".$_SESSION['ska_reply_dateSelesaiPRO']."', now())";

    $result=sqlrun($sql);

    /* $sql4 = "INSERT INTO ska_log(ska_log_dateCreate, ska_log_noAdu, ska_log_adm_id, ska_log_trans, ska_log_lokasi, ska_log_dataLama, ska_log_dataBaru)

    VALUES(now(), '$desc/$tahun/$bil', '0', 'add', '0', '0', '0')";
       
    if(!mysql_query($sql, $connection))
    {
    die('Error:'.mysql_error());
    }
     */


    ?>


    Sponsored content

    Re: bagaimana nak buat function utk upload file (doc,pdf,jpg,dsb...)dalam php?

    Post by Sponsored content Today at 6:42 pm


      Current date/time is Sat Dec 10, 2016 6:42 pm