i did it .. but i had a problem in getting back the file
the index code is :
<form enctype ="multipart/form-data"
action="upload.php" method="post">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
<input type="hidden" value="done" name="filled">
</form>
the upload file is :
$fp = fopen($_FILES['userfile']['tmp_name'], "rb");
while(!feof($fp))
{
$file_contents .= fread($fp, 1024);
//fread is binary safe
}
fclose($fp);
$file_contents = addslashes($file_contents);
$file_contents = addcslashes($file_contents, "\0");
$file_mime= $_FILES['userfile']['type'];
$file_name= $_FILES['userfile']['name'];
$file_size= $_FILES['userfile']['size'];
$con=@mysql_pconnect('localhost','root','');
$db=@mysql_select_db('uploads',$con);
mysql_query("insert into uploaded
(file_mime,file_contents,file_name,file_size) VALUES (\"$file_mime\",\"$file_contents\",\"$file_name\",\" $file_size\")");
$id=mysql_insert_id($con);
echo "<br> your upload was sucessful ...
your can view it
<a href=getback.php?id=$id target=blank>here</a>";
the Getback file is :
$con=@mysql_pconnect('localhost','root','');
$db=@mysql_select_db('uploads',$con);
$result=mysql_query("select file_name,file_mime,file_contents,file_size from uploaded where id=$id");
$file=mysql_fetch_array($result);
extract($file) ;
header("Content-type: $file_mime");
header("Content-disposition: filename=$file_name");
header("Content-Transfer-Encoding: binary\n");
print( $file_contents);
the Erorr Code is in the Getback file :
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\phpdev5\www\test\getback.php on line 5
Warning: extract() expects first argument to be an array in c:\phpdev5\www\test\getback.php on line 6
Warning: Cannot add header information - headers already sent by (output started at c:\phpdev5\www\test\getback.php:5) in c:\phpdev5\www\test\getback.php on line 7
Warning: Cannot add header information - headers already sent by (output started at c:\phpdev5\www\test\getback.php:5) in c:\phpdev5\www\test\getback.php on line 8
Warning: Cannot add header information - headers already sent by (output started at c:\phpdev5\www\test\getback.php:5) in c:\phpdev5\www\test\getback.php on line 9