I am getting the following error in my little applet to upload images to my database. The script connects to the database no problem. It even creates a new entry. But the entry is blank, and my browser spits out the above mentioned error. Whats wrong in my code? submit.php <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="10000000"> <br>File to upload:<br> <input type="file" name="form_data" size="40"> <p><input type="submit" name="submit" value="submit"> </form> Code (markup): upload.php <?php mysql_connect("localhost","jason","password"); mysql_select_db("test"); $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://192.168.1.66/submit.php> Click Here</a>"; ?> Code (markup):
Line 4 must be $data = addslashes(fread(fopen($_FILES['form_data'], "r"), filesize($_FILES['form_data']))); Try after editing and let me know if it works
^^ Neither. It should be: $data = addslashes(fread(fopen($_FILES['form_data']['name'], "r"), filesize($_FILES['form_data']['name']))); PHP: or $_FILES['form_data']['tmp_name'] if you haven't moved the file yet.
$data = addslashes(fread(fopen($_FILES['form_data']['tmp_name'], "r"), filesize($_FILES['form_data']['tmp_name'])));