Reaper0167 Posted January 28, 2009 Share Posted January 28, 2009 <?php include "msdata.php"; $PSize = filesize($location); $location = addslashes(fread(fopen($location, "r"), $PSize)); mysql_connect($host,$username,$password) or die("Unable to connect to MySQL."); mysql_select_db($db_name) or die("No database found."); mysql_query("INSERT INTO $tbl_name(pic)VALUES('$location')") or die("Operation unable to perform."); ?> Quote Link to comment https://forums.phpfreaks.com/topic/142812-anyone-see-what-is-wrong-with-this-simple-image-upload-script/ Share on other sites More sharing options...
dennismonsewicz Posted January 28, 2009 Share Posted January 28, 2009 what error messages are you getting? Quote Link to comment https://forums.phpfreaks.com/topic/142812-anyone-see-what-is-wrong-with-this-simple-image-upload-script/#findComment-748563 Share on other sites More sharing options...
Reaper0167 Posted January 28, 2009 Author Share Posted January 28, 2009 Warning: fread(): supplied argument is not a valid stream resource in D:\Hosting\3388298\html\mylahstone\upload.php on line 5 what exactly do these 2 lines accomplish?? $PSize = filesize($location); $location = addslashes(fread(fopen($location, "r"), $PSize)); Quote Link to comment https://forums.phpfreaks.com/topic/142812-anyone-see-what-is-wrong-with-this-simple-image-upload-script/#findComment-748568 Share on other sites More sharing options...
lordshoa Posted January 28, 2009 Share Posted January 28, 2009 Do you not open before you read ? Quote Link to comment https://forums.phpfreaks.com/topic/142812-anyone-see-what-is-wrong-with-this-simple-image-upload-script/#findComment-748574 Share on other sites More sharing options...
premiso Posted January 28, 2009 Share Posted January 28, 2009 Why try and combine that into one line? <?php include "msdata.php"; $PSize = filesize($location); $fh = fopen($location, "r") or die("Unable to open file at location $location"); $location = addslashes(fread($fh, $PSize)); mysql_connect($host,$username,$password) or die("Unable to connect to MySQL."); mysql_select_db($db_name) or die("No database found."); mysql_query("INSERT INTO $tbl_name(pic)VALUES('$location')") or die("Operation unable to perform."); ?> See what that gives ya. Quote Link to comment https://forums.phpfreaks.com/topic/142812-anyone-see-what-is-wrong-with-this-simple-image-upload-script/#findComment-748575 Share on other sites More sharing options...
dennismonsewicz Posted January 28, 2009 Share Posted January 28, 2009 well first you have to fopen something before you can fread it lol... http://us.php.net/manual/en/function.fopen.php http://us.php.net/manual/en/function.fread.php http://us.php.net/manual/en/function.filesize.php Those are all the preset functions you are using... they can explain it better than me Quote Link to comment https://forums.phpfreaks.com/topic/142812-anyone-see-what-is-wrong-with-this-simple-image-upload-script/#findComment-748576 Share on other sites More sharing options...
premiso Posted January 28, 2009 Share Posted January 28, 2009 well first you have to fopen something before you can fread it lol... http://us.php.net/manual/en/function.fopen.php http://us.php.net/manual/en/function.fread.php http://us.php.net/manual/en/function.filesize.php Those are all the preset functions you are using... they can explain it better than me He was opening it. If you look at the OP it is just in the same line as fread. Quote Link to comment https://forums.phpfreaks.com/topic/142812-anyone-see-what-is-wrong-with-this-simple-image-upload-script/#findComment-748579 Share on other sites More sharing options...
dennismonsewicz Posted January 28, 2009 Share Posted January 28, 2009 in his initial code he is reading it before opening it... i didn't think that syntax would work Quote Link to comment https://forums.phpfreaks.com/topic/142812-anyone-see-what-is-wrong-with-this-simple-image-upload-script/#findComment-748592 Share on other sites More sharing options...
lordshoa Posted January 28, 2009 Share Posted January 28, 2009 Yes but wasn't the operation reading then opening rather than opening then reading ? or does it mean read the open file ? $location = addslashes(fopen(fread($location, "r"), $PSize)); And your code is doing the same thing but split in to variables instead what difference would it make ? Quote Link to comment https://forums.phpfreaks.com/topic/142812-anyone-see-what-is-wrong-with-this-simple-image-upload-script/#findComment-748601 Share on other sites More sharing options...
premiso Posted January 28, 2009 Share Posted January 28, 2009 in his initial code he is reading it before opening it... i didn't think that syntax would work Explain to me how this is reading it before opening it: $location = addslashes(fread(fopen($location, "r"), $PSize)); Order of operations, items inside the parenthesis get executed first. And your code is doing the same thing but split in to variables instead what difference would it make ? My code may do the same thing, but it provides an error message incase that file is not there to open. That and it makes less confusion to people so that you know the file is being opened before being read. Quote Link to comment https://forums.phpfreaks.com/topic/142812-anyone-see-what-is-wrong-with-this-simple-image-upload-script/#findComment-748609 Share on other sites More sharing options...
dennismonsewicz Posted January 28, 2009 Share Posted January 28, 2009 $location = addslashes(fread(fopen($location, "r"), $PSize)); nevermind... i see it now... LONG night.. my bad Quote Link to comment https://forums.phpfreaks.com/topic/142812-anyone-see-what-is-wrong-with-this-simple-image-upload-script/#findComment-748615 Share on other sites More sharing options...
Reaper0167 Posted January 28, 2009 Author Share Posted January 28, 2009 Unable to open file at location...... that is the error now. <?php include "msdata.php"; $PSize = filesize($location); $fh = fopen($location, "r") or die("Unable to open file at location."); $location = addslashes(fread($fh, $PSize)); mysql_connect($host,$username,$password) or die("Unable to connect to MySQL."); mysql_select_db($db_name) or die("No database found."); mysql_query("INSERT INTO $tbl_name(pic)VALUES('$location')") or die("Operation unable to perform."); ?> Quote Link to comment https://forums.phpfreaks.com/topic/142812-anyone-see-what-is-wrong-with-this-simple-image-upload-script/#findComment-748625 Share on other sites More sharing options...
premiso Posted January 28, 2009 Share Posted January 28, 2009 Unable to open file at location...... that is the error now. Is location even defined? Given that code, I do not see where it is defined, that and you removed my $location part. Please add that back in re-report the error. The reason I had that in there is so you could see what file was trying to be opened and that will help you out 10 times more than not echoing it out. $fh = fopen($location, "r") or die("Unable to open file at location: $location"); Display that error here or even better look at it and figure out why the file is not at that location. Quote Link to comment https://forums.phpfreaks.com/topic/142812-anyone-see-what-is-wrong-with-this-simple-image-upload-script/#findComment-748628 Share on other sites More sharing options...
lordshoa Posted January 28, 2009 Share Posted January 28, 2009 Thank you for explaining you learn things every day. Quote Link to comment https://forums.phpfreaks.com/topic/142812-anyone-see-what-is-wrong-with-this-simple-image-upload-script/#findComment-748637 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.