fopen problem<

liunx

Guest
Quite a while since I was last here but I've now got another one:

when I'm trying to access a script to post some variables to it. I'm using fopen but every time I run my script I get an error message appearing saying: "Message too long".

I've tried looking this one up but have had no joy.

If anyone has any ideas please get back to me.

Regards

Iancan you show the code?86 $file = fopen('http://somefile.php', 'r+');
87fwrite($file,$str);
88 fclose($file);

That I believe is the suspect code - I guess because it's having problems with the connnection (line 86) the following error code occurs with the other two lines (87 & 88)

Supplied argument is not a valid File-Handle resourceon <!-- m --><a class="postlink" href="http://ca.php.net/manual/en/function.fopen.php">http://ca.php.net/manual/en/function.fopen.php</a><!-- m --> check the first comment that's listed

If you want to open large files (more than 2GB) that's what I did and it works: you should recompile your php with the CFLAGS="-D_FILE_OFFSET_BITS=64" ./configure etc... This tells to your compiler (I tested only gcc on PHP-4.3.4 binary on Linux and Solaris) to make the PHP parser binary large file aware. This way fopen() will not give you the "Value too large for defined data type" error message.Originally posted by ianprhead
86 $file = fopen('http://somefile.php', 'r+');
87fwrite($file,$str);
88 fclose($file);

That I believe is the suspect code - I guess because it's having problems with the connnection (line 86) the following error code occurs with the other two lines (87 & 88)

Supplied argument is not a valid File-Handle resource
fopen('http://somefile.php', 'r+');

why do you have the http:// in tehre. that is for websites

fopen('somefile.php', 'r+');Yes I was trying to connect to someone elses script (I did have their permission guv) hence the http://

I've now found out the problem - apparently you cannot POST using fopen but you need to GET, so if anyone is using fopen in future remember to include your variables as part of the url kiddies.

This message was sponsored by the letters f and o... you get the idea.

Thanks everybody for trying to answer my problem. I'm sure I'll be back in the future - so until the next time....well glad you have it fixed but POST and GET have nothign to do with the php file you just opened. the file you opened goes into an array, not to do with POST.

fopen('http://somefile.php', 'r+');


that si still illegal, unless you left off the url for security sake, but then again you never said anything to the fact so as far as we know you just forgot which would not open anything.Yes sorry should of said.

My employer would not agree to me posting the complete url so had to replace it with above.

tried to just fopen the url and fwrite $str which contains the variables into it, thinking that would do it. but apparently the variables need to be passed as part of the url in the same way they show in the address bar if GET is used.

Is this a pecularity of the particular script I was trying to access or is it always the case?GET and POST have nothing to do with writing to files. they just send information to scripts. it gets there either way. i dont see why using get would have any effect on it writing or not, unless theres some sort of restriction on it or something.

i didnt even know you could write to files on another server. wouldnt that be an incredibly huge security risk, since if you had any script where you wrote to a file, any person could write to it, even if its on a different server? i dont think you can even do that.ok, this is the way I understand it.

fopen('http://somefile.php', 'r+');

you said that it needed to use GET, well then you need the variables in order for somefile.php to work?

that is what I don't understand. when you fopen a file it puts it in an array, how are get variables going to work on that if you don't out put the array? then if you did that then the GET variables would have to come from your site and not the site you got the file from.

did I confuse anybody else besides me?fopen does not put it into an array. file() reads it into an array. fopen just open it in whatever mode you want. r+ opens it for reading and writing and sets the pointer at the end...or something like that, i dont remember.so then explain what you do with it after you fopen? besides fwrite. what is the contents of $file

$file = fopen("file.php" "r");

what is the contents of $file?$file is just the file handling resource. you use it with fwrite to tell what open resource to write to. come on scoutt, you should know this XD

like with ftp connection, you have a connection resource, or with mysql_connect, you assign it to a variable to use as a resource with mysql_select_db.if you want to post some variable to another script with php, you can with fsockopen...

but if get is ok then you can just
$result = implode('',file('http://address/page.php?var=value'));Originally posted by n8thegreat
$file is just the file handling resource. you use it with fwrite to tell what open resource to write to. come on scoutt, you should know this XD

like with ftp connection, you have a connection resource, or with mysql_connect, you assign it to a variable to use as a resource with mysql_select_db.
exactly my point. GET or POST have no effect on an fopen. I didn't mean to say array but a resource id. I just had array on my mind for some reason.Right guys - totally lost me now

this was my solution

$str = join("&",$eqs);

$file=fopen 'http://somefile.php?'.$str, 'r+');
fwrite($file,$str);
fclose($file);

where $eqs is an array (and I mean array) containing the variables to send

this is joined to form a string variable $str which contains all variables seperated by &

$str is then tagged to the end of the url in the same way as GET tags variables to the end in the address bar. I'm using GET and POST as an analogy - only because that was how it was explained to me. I'm not sure if I even needed fwrite at all - but it works now so I'm leaving it in!so, what exactly did it write to the end of the file? $str? cause tha tis all you told it to do. fopen doesn't run the code does it?$str contains all the variables and values that are then parsed out by the script I connected to.I still don't get it. how is writing to the file making the file run? if you just wanted to run it why use fopen? all you did was send varaibels to it and then save those variables to the file on your server.Ah that'll be the bit I don't understand either, it's not my script I'm sending it to.

Just following instructions given and yet again being forced to realise there are people out there a lot cleverer than I am.the way you code it, it send GET value of str and add str to the end of the file...
do you want both?

if you want to send value to a scrip but not modify this script then you should not fwrite to it!!

if it was local and you had to right to write, it would add $str to the end of the file making it like this

// some php code
?>
var1=value1&var2=value2


if you want the answer of the file after submitting value, then you should use fread or file or something else (to know if it succeed of failed)if you just wanted to send values to it why even use file or fread or fopen. just use the url normally.

that is what's confusing me.well scoutt, if you want script1 to send value to script2, how would you write the url in the piece of php code??I forgot about the script1, but I would use include then, not fopen, but if you knew the variables or even if they were dynamic it could still be a link or even curl could do it. many other ways to send variables to anthore script that is not on your server. just saving it is throwing me.
 
Top