Receiving 'Warning: fread(): supplied argument is not a valid stream resource . . . ' when script below is used. Feedback welcome re this problem and 'not valid stream resource' in general.
<html>
<head><title>Image Upload</title></head>
<body>
<?php
// Address error handling.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
if (isset ($_POST['submit'])) { // if form submitted, connect, upload, etc.
// Connect and select.
$host="localhost";
$user="user";
$password="whatever";
$database="binary_data";
if ($dbc = @mysql_connect ($host,$user,$password)) {
if (!@mysql_select_db ($database)) {
die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>');
}
} else {
die ('<p>Could not connect to MySQL because: <b>' . mysql_error() . '</b></p>');
}
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
$result=MYSQL_QUERY("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
"VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";
MYSQL_CLOSE();
} else {
// else show the form to submit new data:
?>
<form method="post" action="image_up.php" enctype="multipart/form-data">
Image Description:<br>
<input type="text" name="form_description" size="40">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>Image file to upload/store in database:<br>
<input type="file" name="form_data" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
</body>
</html>