|
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 #1 Asiafever's post
nak jadik blob kat dbms ke? |
|
|
|
|
|
|
|
erm ... tak.... kalau nak letak dlm file system la.... |
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
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;
}
?> |
|
|
|
|
|
|
|
wah.... thank you.... |
|
|
|
|
|
|
|
Reply #6 Asiafever's post
dia punya tu simpan sbg blob (binary) dlm dbms tau.. |
|
|
|
|
|
|
|
ya..... tapi saya juga menghargai niat baiknya juga... |
|
|
|
|
|
|
|
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.... |
|
|
|
|
|
|
|
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 #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. |
|
|
|
|
|
|
|
Haha... tapi user tak nak ada limitation untuk input file tu.... kalau tak heheheheehe |
|
|
|
|
|
|
|
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). |
|
|
|
|
|
|
|
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..... |
|
|
|
|
|
|
| |
|