Jump to content

file() not working... php configuration question


Recommended Posts

Hello,

Thank you everyone before hand. I really appreciate this. I don't generally ask questions, I find everything I need searching through the forums. Yet this one is a bit more challengins because it doesn't depend on me that much.

Mainly I have a code that works fine with my hosting account. Now, my client decided to keep using his provider although I told him to switch. I knew there was something fishy with them and now I discover they have no idea about anything. They run a server and don't know what php is, for example.

[url=http://www.brechen.com/phpinfoResults.html]http://www.brechen.com/phpinfoResults.html[/url]

So yes, my question is more about the php.ini config file. I'm trying to retrieve some text into an array with the file() function and it's not working on their site, though it works in mine.

They're running PHP Version 4.3.1. I'm sending part of the configuration I got from phpinfo(). allow_url_fopen is on for local and master. What else should I look for? If you need more info let me know.

I've tested opening files locally and it works fine. The problem is doing it with external urls. I'm trying to open a url that points to some cgi/php script result but even when I try with a simple txt file, file() returns false on this hosting account. Mine, like I said, works fine.

I'm basically just using this:

$lines = file_get_contents('http://some.url.here');

if ($lines){
  echo 'ok';
}else{
    echo 'not working';
}

My script does some other stuff but I'm keeping it simple while I try and find out how to try and find what needs to be changes from the php configuration (if that is the problem). If it is I'll contact them and try to make them change it... somehow.  :-\

Thank you.  :)

squal
file() doesnt work for you, and file_get_contents() does? are you using file () correctly? because file gets the txt lines as arrays, therefore you need to:
$lines = file("text.txt");
foreach ($lines as $line) {echo $line;}
Ted
Thanks for the quick response!

Yes, the file exists. Like I said I tested it with both sites. one works, the other (the one of the phpinfo file I sent) doesn't.

I tested many files. Even a txt file to make it easier for it but it only works locally. Outside links don't work. PHP is running on an Win NT on that server. My hosting runs on Linux. Any difference there? I tried checking for file permissions, just in case. But NT seems to work differently (sorry about my ignorance about NT servers).

file_get_contents() Doesn't work either on that site.

I am using it correctly because, like I said, it works locally on the NT server and works with everything on my hosting.

This is the original code on my hosting. This is what I really need:

<?php

// capture the output of pictage page
$lines = file('http://external.pictage.com/external/PHTINTEG?photog=RV003&color=#000000&text=#ffffff');

$numberX=1;

if ($lines){
foreach($lines as $count => $line){
if (ereg('^<br><a*', $line)){

print "linkN".$numberX."=".urlencode($line)."&";
$numberX++;
};
};
}else{
[color=red]print "file not opened \n";[/color]
};


?>

This is being sent to a Flash movie and it works fine. on the other site I get the result [b]file not opened[/b]. It just cleans the <a> tags from the result (that and all the head stuff from an html doc).

But like I said, I have no problems with the code, it's working. You can try it here:

http://www.brechen.com/rodrigo/newSite/substract.php

The one not working is here:

http://www.rodrigovarelaphotography.com/newsite/substract.php

This will print [color=red]file not opened[/color].

Thanks again.
Thanks a lot, Orio.  ;D

I did everything, in case it helps. But it looks bad. I'm not very experienced in php but the error message doesn't look good and with this hosting people who have no idea of php it's going to be tricky:

error_reporting(E_ALL); returned this:

file not opened PHP Warning: file() [function.file]: php_hostconnect: connect failed in C:\Program Files\Ensim\SiteData\webppliance\conf\domains\weddingcom\Inetpub\wwwroot\newsite\substract.php on line 6 PHP Warning: file(http://external.pictage.com/external/PHTINTEG?photog=RV003&color=#000000&text=#ffffff) [function.file]: failed to create stream: Bad file descriptor in C:\Program Files\Ensim\SiteData\webppliance\conf\domains\weddingcom\Inetpub\wwwroot\newsite\substract.php on line 6

line 6 is the file command, actually. At the moment I have that url which has no extension. But I tried a text file and:

PHP Warning: file() [function.file]: php_hostconnect: connect failed in C:\Program Files\Ensim\SiteData\webppliance\conf\domains\weddingcom\Inetpub\wwwroot\newsite\substract2.php on line 8 PHP Warning: file(http://www.brechen.com/rodrigo/newSite/image_sizes.txt) [function.file]: failed to create stream: Bad file descriptor in C:\Program Files\Ensim\SiteData\webppliance\conf\domains\weddingcom\Inetpub\wwwroot\newsite\substract2.php on line 8

Same thing. Like 8 is the file function in this case. Script is the same just pressed more times the return to leave spaces I suppose. ;-)

var_dump(ini_get("allow_url_fopen")); returned string(1) "1" which is what you were expecting, I think.

Thanks a lot.

squal
Thanks Orio. I did try it but I got a similar error:

[code]file not opened PHP Warning: file(http%3A%2F%2Fexternal.pictage.com%2Fexternal%2FPHTINTEG%3Fphotog%3DRV003%26color%3D%23000000%26text%3D%23ffffff) [function.file]: failed to create stream: No such file or directory in C:\Program Files\Ensim\SiteData\webppliance\conf\domains\weddingcom\Inetpub\wwwroot\newsite\substract.php on line 6[/code]

Now, did I do what you asked me properly? I did:

[code]$lines = file(urlencode ('http://external.pictage.com/external/PHTINTEG?photog=RV003&color=#000000&text=#ffffff'));[/code]

Was that right?

Thanks.
My mistake. Try it this way:

[code]$lines = file("http://external.pictage.com/external/PHTINTEG?photog=".urlencode("RV003")."&color=".urlencode("#000000")."&text=".urlencode("#ffffff"));[/code]

If this [i]still[/i] doesnt work, according to some bug reports I went over ([url=http://bugs.php.net]bugs[/url]) there were a few problems with file system functions in PHP 4-4.3, some had to do with numbers in urls, some were general. If the last option I wrote above doesn't work, I don't have another suggestion but to upgrade your PHP version...

Orio.

Orio.
Thanks Orio.

It didn't work and I'm thinking it's either a bug like you say or PHP not properly installed on the Windows NT system this people have.

Anyway, I will try and make my client get rid of them since they don't know what they're doing.

Thanks a lot for the help.  ;D

squal
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.