file-get-contents

Perl command or module like Linux “file” command

十年热恋 提交于 2019-12-05 20:30:13
I have a script that downloads files but these files do not have any information about them before they are downloaded. While writing for Linux I have just called qx{ 'file ' . $filename } to see if it is a JPEG image an if not delete it. However, I am now trying to rewrite to a platform independent and pure-Perl form. I have turned all the calls to system{ 'curl', $image_website } to LWP::UserAgent calls and I was hoping that there is some way to replace calls to file with something as well. File::Type CPAN module can help you - its description is "determine file type using magic" which is

How to use file_get_contents on Ajax site

限于喜欢 提交于 2019-12-05 18:03:34
When you use file_gets_contents($website) or cURL to load a website, does it load the whole website? I am mostly interested about using cURL . I am using it to load a webpage that then gets some contents such as price using AJAX and it has some problems getting the prices. When I use file_get_contents, does it load as normally as a whole website does on a browser plus the stuff loaded using Ajax? No. Using file_get_contents() will only return the page contents, it will not execute any JavaScript on the page itself. The analog of this behaviour is almost equivalent to "View Page Source" in a

HTTP/1.1 505 HTTP Version Not Supported

試著忘記壹切 提交于 2019-12-05 18:01:35
问题 I'm running a PHP script to grab a web page. It worked fine with many sites, but with one site it fails, returning an error saying "HTTP/1.1 505 HTTP Version Not Supported". This is (part of) my script: for($i = 0; $i < 1; $i++) { $page = file_get_contents("http://www.lovelybooks.de/stoebern/empfehlung/romantic fantasy/?seite=$i"); // do something with $page } Many answers recommend setting the HTTP version explicity. I have tried setting 0.9, 1.0 and 1.1, but it did not change anything. And

PHP basic auth file_get_contents() [duplicate]

梦想与她 提交于 2019-12-05 17:04:23
问题 This question already has answers here : Making a HTTP GET request with HTTP-Basic authentication (4 answers) Closed 4 years ago . I need to parse some XML data from a website. The XML data is in raw format, but before I need to authentificate (basic webserver based auth, with username & password). I tried: $homepage = file_get_contents('http://user:password@IP:PORT/folder/file'); but I get the following error: failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized PHP seems to

reCaptcha file_get_contents(): SSL operation failed

泪湿孤枕 提交于 2019-12-05 16:20:56
I'm using Google reCaptcha for my webpage. In testing mode everything works fine. No SSL. When I test my webpage in production environment the following errors occures: Warning : file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /vendor/google/recaptcha/src/ReCaptcha/RequestMethod/Post.php on line 68 Warning : file_get_contents(): Failed to enable crypto in /vendor/google/recaptcha/src/ReCaptcha/RequestMethod/Post.php on line 68 Warning : file_get_contents( https://www.google.com

PHP - file_get_contents() with variable in string?

让人想犯罪 __ 提交于 2019-12-05 15:17:12
Im trying to email an order with PHPMailer to the customer when this order is received. I tried doing that this way: $email_page = file_get_contents("email_order_html.php?order=$order_id"); I want to get the contents of this page as string so I can send this with PHPMailer but this function wont execute the page because of the variable $order_id in it, how can I fix this? You can only add Query Params when using file_get_contents with an Url Aware Stream Wrapper, e.g. it would work for http://localhost/yourfile.php?foo=bar . Doing so would issue an HTTP Get Request to a webserver at localhost

file_get_contents not working on production server, fine on local

早过忘川 提交于 2019-12-05 14:49:58
I have a PHP script that fetches an image from a remote server so that I can manipulate it using HTML5 canvas API. <?php if ((isset($_GET['url']))) { $url = $_GET['url']; $file_format = pathinfo($url, PATHINFO_EXTENSION); try { header("Content-Type: image/$file_format"); header("Content-disposition: filename=image.$file_format"); $img = file_get_contents($url); echo $img; } catch(Exception $e) { echo $e->getMessage(); } } else die('Unknown request'); ?> A typical request would look like this: fetch_image.php?url=http://example.com/images/image.png Everything works fine on my local server but

file_get_contents synchronous or asynchronous

佐手、 提交于 2019-12-05 14:25:18
Today I came across one situation. I am using file_get_contents to get token from a file for a user. $data=file_get_contents("http://example.com/aaa.php?user=tester&akey=abcdef1234"); $dec=json_decode($data,true); $tokenid=$dec['message']['result']['tokenid']; Using the token i will call another file to get details; $data=file_get_contents("http://example.com/bbb.php?user=tester&token=".$tokenid); the problem is sometimes i am not getting tokenid, after refreshing the page i get it. There is no problem in aaa.php its working fine. I doubt whether php is not waiting for the response of the file

PHP: “file_get_contents()” returning NULL from content-verified URL

白昼怎懂夜的黑 提交于 2019-12-05 11:43:09
I'm betting that it'll end up being something simple ... but I can use a hand in spotting it. Problem: When I try to get the contents of a specific local URL via file_get_contents() , it comes back as an empty string '' (length=0). What I've tried: $url = 'http://localhost/bbq/index.php/company/get/id/2131/return/json'; $results = file_get_contents($url); echo'<pre>Results:<br />',var_export($results),'</pre>'; When directly visiting http://localhost/bbq/index.php/company/get/id/2131/return/json , everything echos beautifully: {"id":"2131","value":"Acme Anvil Corp."} To check myself, I tried

file_get_contents with empty file not working PHP

▼魔方 西西 提交于 2019-12-05 09:17:48
I try to use file_get_contents form PHP but it's not working. There is my code : $filename = "/opt/gemel/test.txt"; if($filecontent = file_get_contents($filename)){ $nom = fgets(STDIN); file_put_contents($filename, $nom, FILE_APPEND); } else echo "fail"; And my file test.txt is empty. (0 octets). He exists but he is empty. When i write something into it, my code works perfectly but if he is empty my code echo "fails" Why that, why he can't open the file text.txt ? The function file_get_contents returns the string that's in the file. If the file contains no data, then file_get_contents returns