Page 1 of 1

Warning: fread(): supplied argument is not a valid stream

Posted: Mon May 21, 2007 9:56 am
by phpDVWeaver
am trying to upload images in MySql using php. whenever I run the following code I get this message:

Warning: fread(): supplied argument is not a valid stream resource in C:\webs\test\CNST Projects\Genaral Upload Form\figUpload.php on line 6

config.php is where I assign the database, the user, and the password.
openDB.php is where the database is opened
closeDB.php is where the database is closed
$figpath is the php variable that holds the path of the figure to upload (it's an input wher the type is file and the name is figurepath )
php:

Code: Select all

[syntax="php"]
<?php 
include'phpFigures/config.php'; 
include'phpFigures/openDB.php'; 
include'phpFigures/assignValues.php'; 
if (isset($figpath)){ 
$figImage=addslashes(fread(fopen($figpath,"r"),filesize($figpath))); 
$query = "INSERT INTO images(description, image) VALUES ('$figdescription', '$figImage')"; 
mysql_query($query) or die("Query failed: " . mysql_error()); 
echo "The figure is successfully Uploaded!"; 
} 
else{ 
echo "You did not Upload any figure!"; 
} 
include'phpFigures/closeDB.php';
[/syntax]

Re: Warning: fread(): supplied argument is not a valid strea

Posted: Mon May 21, 2007 3:28 pm
by Christopher
How about checking to see if an error occured?

Code: Select all

<?php 
include'phpFigures/config.php'; 
include'phpFigures/openDB.php'; 
include'phpFigures/assignValues.php'; 
if (isset($figpath)){ 
     $fh = fopen($figpath,"r");
     if ($fh !== false){ 
          if (isset($figpath)){ 
               $figImage=addslashes(fread($fh, filesize($figpath))); 
               $query = "INSERT INTO images(description, image) VALUES ('$figdescription', '$figImage')"; 
               mysql_query($query) or die("Query failed: " . mysql_error()); 
               echo "The figure is successfully Uploaded!"; 
          }else{ 
               echo "You did not Upload any figure!"; 
          }
     } else {
          echo "Error opening $figpath";
     } 
}
include'phpFigures/closeDB.php';