Forum Moderators: coopster

Message Too Old, No Replies

file upload into mysql -- pls help

MYSQL file upload issue

         

sjagan

7:51 pm on Jul 23, 2006 (gmt 0)

10+ Year Member



hi phpians,

iam new to php & iam trying to upload files into a mysql database & iam getting this warning after uploading a file.the Data goes into the database , but cannot view it.

Iam following the tutorial from

[php.about.com...]

Warning: fread(): supplied argument is not a valid stream resource in
C:\xampp\xampp\htdocs\test\upload.php on line 4

File ID: 1
File Name:
File Size:
File Type:

None of te file content is displayed -- mysql output after uploading a file.One recorded is uploaded in db

mysql> select * from uploads;
+----+-------------+------+----------+----------+----------+
¦ id ¦ description ¦ data ¦ filename ¦ filesize ¦ filetype ¦
+----+-------------+------+----------+----------+----------+
¦ 1 ¦ NULL ¦ NULL ¦ NULL ¦ NULL ¦ NULL ¦
+----+-------------+------+----------+----------+----------+
1 row in set (0.00 sec)

Script1

<form method="post" action="http://localhost/test/upload.php" enctype="multipart/form-data">
Description:<br>
<input type="text" name="form_description" size="40">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload:<br>
<input type="file" name="form_data" size="40">
<p><input type="submit" name="submit" value="submit">
</form>

upload.php -- upload files got from form to mysql

<?php
mysql_connect("localhost","root","password");
mysql_select_db("kpireports");
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
$result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filesize,filetype) ". "VALUES

('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
$id= mysql_insert_id();
print "<p>File ID: <b>$id</b><br>";
print "<p>File Name: <b>$form_data_name</b><br>";
print "<p>File Size: <b>$form_data_size</b><br>";
print "<p>File Type: <b>$form_data_type</b><p>";
print "To upload another file <a href=http://localhost/test/index.php> Click Here</a>";
?>

download.php -- to download the uploaded files

<?php
mysql_connect("localhost","root","password");
mysql_select_db("kpireports");
$query = "SELECT data,filetype FROM uploads where id=$id";
$result = MYSQL_QUERY($query);
$data = MYSQL_RESULT($result,0,"data");
$type = MYSQL_RESULT($result,0,"filetype");
Header( "Content-type: $type");
print $data;
?>

======

kindly someone tell me what is wrong here.

Appreciate al ut time

THnaks

J

smatts9

3:27 am on Jul 24, 2006 (gmt 0)

10+ Year Member



[dev.mysql.com ]

This is the only thing I could think of that could be going wrong?...