Page 1 of 1

Upload file to MySQL with PHP

Posted: Mon Jun 30, 2008 11:41 pm
by nightkarnation
Hello!

I would really appreciate some help on this one:

Im trying to upload a file into my phpmyadmin (locally) just in case, everything set up correctly and working on the db connection

now heres my php (upload.php):

Code: Select all

<?php 
mysql_connect("localhost","root",""); 
mysql_select_db("learning"); 
$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> Click Here</a>"; 
?>
Heres my file upload form.html code:

Code: Select all

<form method="post" action="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>
And this is what i get when i browse and submit any file:

Warning: fread(): supplied argument is not a valid stream resource in C:\wamp\www\Test\phpAndMysql\upload.php on line 4