4

I am writing some php script to update the code on my sites. In order to do that I have written the following lines which checks for the update version and bring the name from where I use to distribute my updates ans then creates the link of that name. I have done something like this.

$filename = "http://www.hf-live.com/codeupdate/Get_Files_Name.php";
$contents = file_get_contents($filename);
echo $contents;

I am getting this error

failed to open stream: No such file or directory.

Even though the file is present still I am getting the same error. I have turned on my allow_url_fopen to on. The above code is working from my local host but not from the server. I have to update a major bug fix and I am stuck.. Please someone help me soon..

D. Schreier
  • 1,700
  • 1
  • 22
  • 34
Yunus Aslam
  • 2,447
  • 4
  • 25
  • 39
  • 1
    It works fine in my computer. Is it possible that you've been banned? What do you get when you open it in your browser? What does `var_dump($http_response_header);` print? – Álvaro González Dec 03 '13 at 11:16
  • @Alvaro : var_dump($http_response_header); It returns NULL – Yunus Aslam Dec 03 '13 at 11:33
  • Is that the exact code you are using? That works ok, http://codepad.viper-7.com/eP3K6G – Harri Dec 03 '13 at 11:40
  • Yes I am using the same code.. That means, I have some server settings disabled. Or there may be some additional security features added by the server. Can you point out some of them enabling which I could make file_get_contents() work.. ?? – Yunus Aslam Dec 03 '13 at 11:42
  • In the comments to answer below you say that "$filename = "hf-live.com/codeupdate/Get_Files_Name.php";" is the content of your $filename variable. So, what is the exact code that you are using? – Harri Dec 03 '13 at 11:51
  • I am only using these three lines to check for the names of the update I have set $filename = "http://www.hf-live.com/codeupdate/Get_Files_Name.php"; $contents = file_get_contents($filename); echo $contents; which returns me the name of the latest zip set as update which later on is taken through get files content and extracted to my root folder.. I am in strong doubt that some of the setting is turned off .. – Yunus Aslam Dec 03 '13 at 11:54
  • If your $filename does not start with http:// or https:// it will not fetch data over internet. So, just start using the code that you wrote in the actual question and it will work. – Harri Dec 03 '13 at 12:02
  • Now I am getting "failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error"... – Yunus Aslam Dec 03 '13 at 12:17
  • One often runs into this error, and to quickly troubleshoot it, follow these steps : https://stackoverflow.com/a/36577021/2873507 – Vic Seedoubleyew Apr 12 '16 at 15:58

1 Answers1

5

remove extra .php from url

   $filename = "http://www.hf-live.com/codeupdate/Get_Files_Name.php";

You will get error if you are doing this way...

   $filename = "marynyhof.com/Info.php"; // will give you error, which exactly you are getting

use full url like this

   $filename = "http://www.marynyhof.com/Info.php"; //will work
Kalpit
  • 4,906
  • 4
  • 25
  • 43
  • @Yunus for your kind info your script is working fine.. it' showing some .zip file is there – Kalpit Dec 03 '13 at 11:15
  • You are trying from your localhost ?? – Yunus Aslam Dec 03 '13 at 11:17
  • Its working from my local too.. but that is not working from server... try this link "http://marynyhof.com/CustomCheck.php" here you will see the error.. And it has the same code as I have posted above... – Yunus Aslam Dec 03 '13 at 11:19
  • @Yunus - Is that your live page? That `file_get_contents()` is not loading a HTTP document, it's loading a local file! – Álvaro González Dec 03 '13 at 11:25
  • Yes I am sure.. I have been trying that since morning.. and here is the link if you wanna see the info http://marynyhof.com/Info.php .. What do you think I am missing in the code.. – Yunus Aslam Dec 03 '13 at 11:26
  • IF it works on one machine and not another, then I'm guessing one machine has allow_url_fopen set to 0. http://php.net/manual/en/filesystem.configuration.php – Harri Dec 03 '13 at 11:27
  • When I use http:// then some other weird problem occurs.. The page keeps on loading until time out. I have added http://, so that you can run that page and see...Connection timed out .. Just copy the path inside the function and run it, it will work and show that the php exists.. – Yunus Aslam Dec 03 '13 at 11:31
  • I have a site hf-live.com which I use to set the update and distribute to all the other sites. So I have used $filename = "http://www.hf-live.com/codeupdate/Get_Files_Name.php"; which looks for the current update set from all the other sites. In the line above when I use http:// and then from other site if I check for updates, then the page keeps on loading until timeout. So I m trying to check update from marynyhof.com which will look at hf-live.com for any updates and provide it.. – Yunus Aslam Dec 03 '13 at 11:40
  • There is now a troubleshooting checklist for this frequent error here : https://stackoverflow.com/a/36577021/2873507 – Vic Seedoubleyew Apr 12 '16 at 15:58