file-get-contents

File-get-contents failed to open stream Unauthorized

北城以北 提交于 2019-11-29 12:23:44
I am trying to use file_get_contents.I have made sure that allow_url_fopen is enabled in php.ini. As of now it is telling me: [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized All I'm doing is the following, which I can access through browser without a problem. $url=('http://site/@api/users/=john_smith@site.com/properties'); $xmlString=file_get_contents($url); I believe this is an authentication issue but not sure how I can supply the proper credentials from within the script itself. Any ideas would be greatly appreciated. In your url try: http

Handling delays when retrieving files from remote server in PHP

浪子不回头ぞ 提交于 2019-11-29 11:28:26
I am working with PHP to access files and photos from remote servers. I am mostly using the file_get_contents() and copy() functions. Sometimes accessing a small text file or photo is almost instant, but other times it seems to get "stuck" for a minute on the same exact file. And sometimes it actually causes my script to hang, and even when I stop the script Apache remains locked up for several minutes. I'm quite willing to accept the fact that internet connections can be flaky. My concern is that I recover gracefully and that I do not crash Apache - the PHP set_time_limit() function only

Broken image with readfile and file_get_contents

杀马特。学长 韩版系。学妹 提交于 2019-11-29 10:52:26
I'm trying to use a function in order to get this working: <img src='login.php?image=ind_legend.jpg'> But I can't pass through the function to place the image. I went back a couple of steps and tried only this part of the code: <?php $file = "http://localhost/sales/test.jpg"; header('Content-type: image/jpeg'); readfile($file); ?> or using this function: echo file_get_contents($source); but the fact is that the only thing I get is a broken image cross (IE) or nothing in Firefox. I would appreciate any suggestions Thanks in advance You certainly have some whitespace in your PHP script, or a UTF

Urlencode and file_get_contents

冷暖自知 提交于 2019-11-29 10:28:47
We have an url like http://site.s3.amazonaws.com/images/some image @name.jpg inside $string What I'm trying to do (yes, there is a whitespace around the url): $string = urlencode(trim($string)); $string_data = file_get_contents($string); What I get (@ is also replaced): file_get_contents(http%3A%2F%2Fsite.s3.amazonaws.com%2Fimages%2Fsome+image+@name.jpg)[function.file-get-contents]: failed to open stream: No such file or directory If you copy/paste http://site.s3.amazonaws.com/images/some image @name.jpg into browser address bar, image will open. What's bad and how to fix that? The URL you

file_get_contents or curl in php?

99封情书 提交于 2019-11-29 10:22:21
Which of file_get_contents or curl should be used in PHP to make an HTTP request? If file_get_contents will do the job, is there any need to use curl ? Using curl seems to need more lines. eg: curl: $ch = curl_init('http://www.website.com/myfile.php'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $content); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec ($ch); curl_close ($ch); file_get_contents: $output = file_get_contents('http://www.website.com/myfile.php'.$content); First of all cURL has a lot of options to set. You can really set any

php - file_get_contents - Downloading files with spaces in the filename not working

心不动则不痛 提交于 2019-11-29 07:02:57
I am trying to download files using file_get_contents() function. However if the location of the file is http://www.example.com/some name.jpg , the function fails to download this. But if the URL is given as http://www.example.com/some%20name.jpg , the same gets downloaded. I tried rawurlencode() but this coverts all the characters in the URL and the download fails again. Can someone please suggest a solution for this? I think this will work for you: function file_url($url){ $parts = parse_url($url); $path_parts = array_map('rawurldecode', explode('/', $parts['path'])); return $parts['scheme']

Is allow_url_fopen safe? [duplicate]

人盡茶涼 提交于 2019-11-29 06:53:06
This question already has an answer here: Should I allow 'allow_url_fopen' in PHP? 5 answers I am currently using file_get_contents() to get the title of a webpage, given the URL. On wamp, this works perfectly fine. However, when I shifted this to my web server, I came across a problem which lead me to this answer. (Which is to set allow_url_fopen to 1 ). Is there a major security risk in setting this on? If yes, are there any alternate ways to grab the title of a webpage from the URL itself? (Also, unsure of tags for this so please feel free to add/remove if appropriate!) Edit (1) : Further

JSON to PHP Array using file_get_contents

有些话、适合烂在心里 提交于 2019-11-29 05:37:44
I am trying to fetch the below json content using a magazine api. The output of the json is like this. i want the below json to convert to php array. { "bpath": "http://www.sampledomain.com/", "clist": [ { "cid": "11", "display_type": "grid", "ctitle": "abc", "acount": "71", "alist": [ { "aid": "6865", "adate": "2 Hours ago", "atitle": "test", "adesc": "test desc", "aimg": "", "aurl": "?nid=6865", "weburl": "news.php?nid=6865", "cmtcount": "0" }, { "aid": "6857", "adate": "20 Hours ago", "atitle": "test1", "adesc": "test desc1", "aimg": "", "aurl": "?nid=6857", "weburl": "news.php?nid=6857",

php: file_get_contents encoding problem

元气小坏坏 提交于 2019-11-29 04:40:21
问题 My task is simple: make a post request to translate.google.com and get the translation. In the following example I'm using the word "hello" to translate into russian. header('Content-Type: text/plain; charset=utf-8'); // optional error_reporting(E_ALL | E_STRICT); $context = stream_context_create(array( 'http' => array( 'method' => 'POST', 'header' => implode("\r\n", array( 'Content-type: application/x-www-form-urlencoded', 'Accept-Language: en-us,en;q=0.5', // optional 'Accept-Charset: ISO

How to resolve the error “[ErrorException] file_get_contents(/var/www/laravel/.env): failed to open stream: No such file or directory”?

荒凉一梦 提交于 2019-11-29 03:14:37
I'm using Ubuntu 14.04 on my machine. I installed composer and then laravel in the document root i.e. /var/www I also gave -R 777 persmission to folder laravel present in directory /var/www Then I go to directory laravel using cd /var/www/laravel and run the following command php artisan and I got to see all the available commands there. Then I typed in php artisan key:generate and got the error [ErrorException] file_get_contents(/var/www/laravel/.env): failed to open stream: No such file or directory Here I got stuck actually, can someone please help me in this regard? Thanks. Rename .env