CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2253|Reply: 14

Upload file php

[Copy link]
Post time 28-10-2007 03:42 PM | Show all posts |Read mode
kalau nak upload file ke server (tapi dlm development buat kat local je) .... apa field yang perlu saya ada dalam database? File ni jenis image, tak kisah apa extension.... ? Perlu tak temporary name, temporary path dan sebagainya? Boleh tak bagi cadangan sikit? Terima kasih dulu ya!!
Reply

Use magic Report


ADVERTISEMENT


Post time 28-10-2007 04:44 PM | Show all posts

Reply #1 Asiafever's post

nak jadik blob kat dbms ke?
Reply

Use magic Report

 Author| Post time 28-10-2007 05:22 PM | Show all posts
erm ... tak.... kalau nak letak dlm file system la....
Reply

Use magic Report

Post time 28-10-2007 07:17 PM | Show all posts
nk simpan eh.. aku bg insert dalam db la..cilok system lama aku dulu.. hehe.. pandai2 la ko ubahsuai..


nih html + php
ini skrin dia

skrin.php

<form name="impDokumenScanForm" method="post" action="daftarLampiranAction.php" enctype="multipart/form-data">
<TABLE class="input">
            <TR>
              <TD CLASS="label">Fail</TD>
              <TD CLASS="input">

              <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
              <input name="userfile" type="file" id="userfile">


              </TD>
            </TR>
           <input type="hidden" name="method" value='addLampiran'/>
            <input type="submit" value="Simpan">

//--------------------------------



daftarLampiranAction.php

if($_POST['method']=="addLampiran" && $_FILES['userfile']['size'] > 0)
      {
         
/* Set the database access information
   constant
*/
  
  define ('DB_USER','root');
  define ('DB_PASSWORD','');
  define ('DB_HOST','localhost');
  define ('DB_NAME','dbname');
  
/* Make the connection and then select
   the database.
*/
  $dbc = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
  mysql_select_db(DB_NAME);

          session_start();

          $fileName = $_FILES['userfile']['name'];
          $tmpName  = $_FILES['userfile']['tmp_name'];
          $fileSize = $_FILES['userfile']['size'];
          $fileType = $_FILES['userfile']['type'];

          $fp      = fopen($tmpName, 'r');
          $content = fread($fp, filesize($tmpName));
          $content = addslashes($content);
          fclose($fp);

          if(!get_magic_quotes_gpc())
          {
              $fileName = addslashes($fileName);
          }

         $query = "INSERT INTO upload (name, size, type, content) ".
          "VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
          $result = mysql_query($query);


      }


tp ingat create table dulu yea

#
# Table structure for table 'upload'
#

CREATE TABLE upload (
  id int(11) NOT NULL auto_increment,
  name varchar(100) NOT NULL default '',
  type varchar(30) NOT NULL default '',
  size int(11) NOT NULL default '0',
  content mediumblob NOT NULL
  PRIMARY KEY  (id)
) TYPE=MyISAM;
Reply

Use magic Report

Post time 28-10-2007 07:21 PM | Show all posts
selepas insert dlm db.. tentu kita download file kita simpan td tuh kan.. hah amek coding nih.. harhar


<?php
if(isset($_GET['id']))
{
// if id is set then get the file with the id from database

/* Set the database access information
   constant
*/
  
  define ('DB_USER','root');
  define ('DB_PASSWORD','');
  define ('DB_HOST','localhost');
  define ('DB_NAME','dbname');
  
/* Make the connection and then select
   the database.
*/
  $dbc = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
  mysql_select_db(DB_NAME);



$id    = $_GET['id'];
$query = "SELECT name, type, size, content " .
         "FROM upload WHERE id = '$id'";

$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) =  mysql_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;

exit;
}
?>
Reply

Use magic Report

 Author| Post time 28-10-2007 11:41 PM | Show all posts
  wah.... thank you....
Reply

Use magic Report

Follow Us
Post time 29-10-2007 07:56 AM | Show all posts

Reply #6 Asiafever's post

dia punya tu simpan sbg blob (binary) dlm dbms tau..
Reply

Use magic Report

 Author| Post time 29-10-2007 02:45 PM | Show all posts
ya..... tapi saya juga menghargai niat baiknya juga...
Reply

Use magic Report


ADVERTISEMENT


 Author| Post time 29-10-2007 09:26 PM | Show all posts
Macam mana kalau nak upload multiple files tapi guna satu button upload aje? Asia dah dapat untuk menghasilkan browse lain dengan satu button tapi upload button tu tak dapat pulak....
Reply

Use magic Report

Post time 30-10-2007 08:11 AM | Show all posts
sy biasa tak buat camtuh.. sy buat satu button upload utk satu file.. if nk byk buat satu skrin list(PageList.php) yg ada button tambah. iaitu click button tambah, ia akan gi page utk upload file(upload.php).. ble dah upload, click button simpan, file td akan masuk dalam list(PageList.php) td.
Reply

Use magic Report

Post time 30-10-2007 09:35 AM | Show all posts

Reply #9 Asiafever's post

button upload tu button submit la kan? care paling senang, letak je input file tu (yang ade button browse tuh) lebih dari satu.
Reply

Use magic Report

 Author| Post time 30-10-2007 05:34 PM | Show all posts
Haha... tapi user tak nak ada limitation untuk input file tu....   kalau tak heheheheehe
Reply

Use magic Report

Post time 31-10-2007 07:04 PM | Show all posts

Reply #12 Asiafever's post

buat javascript utk write penambahan input tu - kalau user nk tambah input file, dia kena tekan [add] (nama input pun kena dynamic la).
Reply

Use magic Report

 Author| Post time 8-11-2007 01:28 AM | Show all posts
Hehe... timmer kaseh....
Reply

Use magic Report

 Author| Post time 8-11-2007 01:31 AM | Show all posts
Tadi tiba2 terbaca pasal exif.... tapi tak berapa faham penggunaanya? Cuma tau boleh guna untuk ekstrak data mengenai kamera dan data foto dari foto yang telah diupload.....
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

5-1-2025 09:08 AM GMT+8 , Processed in 0.055906 second(s), 28 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list