Saturday, December 5, 2009

Fread: not valid stream resource?

Hi,



I'm getting an error whenever trying to upload a picture to a DB and I get the error message fread(): supplied argument is not a valid stream resource. Does anyone know the problem? My code is shown below.



%26lt;?php



$username = $_POST['session'];



$session = $_SESSION['User']['UserName'];



if ($submit) {



if ($username == $session) {



If($Picture != "none") {



$rawpic = fopen($_FILES['Picture'], "r");



$PSize = filesize($Picture);



$pic = fread($rawpic, $PSize);



$mysqlPicture = addslashes($pic);



mysql_query("INSERT INTO Member (loginName,Image) VALUES ('$username','$mysqlPicture')") or die("Can't Perform Query, $username");



}



}



else {



echo "You did not upload any picture or you are not logged in.";



}



}



?%26gt;



Does anybody know the problem and show me how I can fix it? Thanks. I also have the database config file set up with the right credentials (local host, username, password) in case you were wondering.



Fread: not valid stream resource?concerts



I can't answer your question in regards to this as I have not touched PHP in almost 3 years. However, I can say that you should no be storing the image in the database. That is a huge performance killer. The best way to do this is possibly rename the image to a unique id like a guid and move it to a central image directory. In your database you should provide the url of the image. This way you are only storing a short sized string rather than a representation of the encoded file. Even indexing on that would be pointless.



Remember, when you are working with a database your goal is to store the least amount of information possible to properly reflect the data given. This is why they use a boolean rather than a string that says true or false, or rather they will use a byte to represent different selections as it is smaller than the memory requirements of a string. Just something to keep in mind.

No comments:

Post a Comment

 
ltd