file upload problem
Posted: Mon Aug 11, 2003 12:17 pm
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
<?
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