file upload problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
sulen
Forum Commoner
Posts: 79
Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:

file upload problem

Post by sulen »

I am trying to do a file upload feature into a mysql database. The script that I have written is as under. The script runs and gives me the file uploaded sucessfully mssg but when I go into the Db the corresponding table has no contents.

<?
if (isset($_POST["submit"]))
{

$fname= $_FILES["user_file"]["name"];

$tmp= addslashes($_FILES["user_file"]["tmp_name"]);

$size=$_FILES["user_file"]["size"];

$type=$_FILES["user_file"]["type"];

$fd=fopen($tmp,"r") or die("Can't open file!");

$fdata=urlencode(fread($fd,filesize($tmp)));
$size=filesize($tmp);

MYSQL_CONNECT("localhost","username","password") or die("No DB connect");
mysql_select_db("binary");

$sql="INSERT INTO files (name,file_type,file_data,file_size)".
"VALUES('$fname','$type','$fdata','$size')";
mysql_query($sql) or die("Can't execute query!".mysql_error());

}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Uploading A File</title>
</head>
<body>

<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">

Send this file: <input name="user_file" type="file">
<input type="submit" value="Send File" name="submit">
</form>

</body>
</html>


Please help me out here and tell me what I am doing wrong. Thnks
Post Reply