Jump to content

anyone see what is wrong with this simple image upload script


Reaper0167

Recommended Posts

<?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."); 

?>

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));

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.

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

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.

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 ?

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.

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."); 

?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.