file-get-contents

PHP file_get_contents does not work on localhost

馋奶兔 提交于 2019-11-26 17:03:37
问题 I am working on my website from localhost (http://172.16.65.1/) a MAMP server on OSX. I want to load some JSON from Google and some simple tests show me I have a problem here.. echo file_get_contents("http://www.google.com"); // FAILS // PHP log: [07-Dec-2011 23:09:21] PHP Warning: file_get_contents(http://www.google.com) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: Host is down in /Applications/MAMP/htdocs/-tests/get-json.php on line 3 echo

PHP Get Content of HTTP 400 Response

落爺英雄遲暮 提交于 2019-11-26 16:45:01
问题 I am using PHP with the Amazon Payments web service. I'm having problems with some of my requests. Amazon is returning an error as it should, however the way it goes about it is giving me problems. Amazon returns XML data with a message about the error, but it also throws an HTTP 400 (or even 404 sometimes). This makes file_get_contents() throw an error right away and I have no way to get the content. I've tried using cURL also, but never got it to give me back a response. I really need a way

file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known

故事扮演 提交于 2019-11-26 14:43:15
I'm trying to download an image from a server using a PHP script on my website on xampp server. The image is being downloaded using the function file_get_contents. The php code for downloading on the server is: if(isset($_GET['path']) && isset($_GET['username'])) { echo "path:".$_GET['path']; $temp = explode(".", $_GET['path']); $extension = end($temp); $fname="images/".$_GET['title']; $filenameIn = $_GET['path']; $filenameOut = "" . $fname; $contentOrFalseOnFailure = file_get_contents($filenameIn); $byteCountOrFalseOnFailure = file_put_contents($filenameOut,$contentOrFalseOnFailure); } But I

Why I&#39;m getting 500 error when using file_get_contents(), but works in a browser?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 13:29:50
$html = file_get_contents("https://www.[URL].com"); echo $html; produces this in the error logs: PHP Warning: file_get_contents(https://www.[URL].com) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in /Applications/MAMP/htdocs/test.php on line 13"; However, the site works fine in a browser. I tried using cURL as well. I don't get any errors in the log file, but $html now echoes: Server Error in '/' Application. Object reference not set to an instance of an object. ...some more debugging info Any ideas how to work around this? blang

Get file content from URL?

二次信任 提交于 2019-11-26 12:24:30
问题 When I use following URL in browser then it prompt me to download a text file with JSOn content. https://chart.googleapis.com/chart?cht=p3&chs=250x100&chd=t:60,40&chl=Hello|World&chof=json (Click above URL see downloaded file content) Now I want to create a php page. I want that when I call this php page, it should call above URL and get content(json format) from file and show it on screen. How can I do this ?? 回答1: Depending on your PHP configuration, this may be a easy as using: $jsonData =

How to get the content-type of a file in PHP?

天大地大妈咪最大 提交于 2019-11-26 10:35:21
I'm using PHP to send an email with an attachment. The attachment could be any of several different file types (pdf, txt, doc, swf, etc). First, the script gets the file using "file_get_contents". Later, the script echoes in the header: Content-Type: <?php echo $the_content_type; ?>; name="<?php echo $the_file_name; ?>" How to I set the correct value for $the_content_type ? I am using this function, which includes several fallbacks to compensate for older versions of PHP or simply bad results: function getFileMimeType($file) { if (function_exists('finfo_file')) { $finfo = finfo_open(FILEINFO

Simple html dom file_get_html not working - is there any workaround?

扶醉桌前 提交于 2019-11-26 09:44:43
问题 <?php // Report all PHP errors (see changelog) error_reporting(E_ALL); include(\'inc/simple_html_dom.php\'); //base url $base = \'https://play.google.com/store/apps\'; //home page HTML $html_base = file_get_html( $base ); //get all category links foreach($html_base->find(\'a\') as $element) { echo \"<pre>\"; print_r( $element->href ); echo \"</pre>\"; } $html_base->clear(); unset($html_base); ?> I have the above code and I\'m trying to get certain elements of the Play Store page but it isn\'t

file_get_contents when url doesn&#39;t exist

你说的曾经没有我的故事 提交于 2019-11-26 09:09:03
问题 I\'m using file_get_contents() to access a URL. file_get_contents(\'http://somenotrealurl.com/notrealpage\'); If the URL is not real, it return this error message. How can I get it to error gracefully so that I know that the page doesn\'t exist and act accordingly without displaying this error message? file_get_contents(\'http://somenotrealurl.com/notrealpage\') [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in myphppage.php on line 3 for

How to get file_get_contents() to work with HTTPS?

六月ゝ 毕业季﹏ 提交于 2019-11-26 08:50:09
问题 I\'m working on setting up credit card processing and needed to use a workaround for CURL. The following code worked fine when I was using the test server (which wasn\'t calling an SSL URL), but now when I am testing it on the working server with HTTPS, it\'s failing with the error message \"failed to open stream\". function send($packet, $url) { $ctx = stream_context_create( array( \'http\'=>array( \'header\'=>\"Content-type: application/x-www-form-urlencoded\", \'method\'=>\'POST\', \

Get content between two strings PHP

℡╲_俬逩灬. 提交于 2019-11-26 08:44:02
Whats is the best way to obtain the content between two strings e.g. ob_start(); include('externalfile.html'); ## see below $out = ob_get_contents(); ob_end_clean(); preg_match('/{FINDME}(.|\n*)+{\/FINDME}/',$out,$matches); $match = $matches[0]; echo $match; ## I have used .|\n* as it needs to check for new lines. Is this correct? ## externalfile.html {FINDME} Text Here {/FINDME} For some reason this appears to work on one place in my code and not another. Am I going about this in the right way? Or is there a better way? Also is output buffer the way to do this or file_get_contents? Thanks in