I crawled a web to get pdf documents in the web. for example, I got 9 PDFs documents from it, and the copy process for 8 PDFs runs well, except for one document. I don't know what's wrong, I've no problem with the connection. when I check out the url directly, it's ok too, I can get that document manually. The url starts with https, it that https problem? how to solve it? I use copy function :
copy($pdfLink, $savePath . basename($pdfLink));
the error result is :
Warning: copy(https://www.aclweb.org/anthology/J/J08/J08-1004.pdf) [function.copy]: failed to open stream: Invalid argument in D:\AppServ\www\suksesfunctionWrapper.php on line 19
Sounds to me like you need tweak a setting in php.ini file so you can make a https request. If you are hard coding the URL just replace https to http.
You might need to enable ssl in php as the file is from a https source.
I believe the extension enable is openssl. Look for the line that loads the php_openssl.dll in the php.ini and uncomment that.
Try this:
$opts = array(
"ssl"=>array(
"allow_self_signed"=>true,
"verify_peer"=>false,
"verify_peer_name"=>false
)
);
copy($pdfLink, $savePath . basename($pdfLink), stream_context_create($opts));
Related
Description
This error:
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14095126:SSL routines:ssl3_read_n:unexpected eof while reading
returns when:
$file = file_get_contents($url['url'], false, stream_context_create($arrContextOptions));
Steps to Reproduce
Video to download:
https://www.youtube.com/watch?v=r5NzAksjfDI
Extract the video id:
$video_id = $yt->extractVideoId(implode($url));
Get the downloadable url
$links = $yt->getDownloadLinks($video_id, $selector = 'video');
Get the array key for the specified video quality etc.
$arrayindex = array_search('mp4, video, 1080p, audio', array_column($links, 'format'));
Set $url to array
$url = $links[$arrayindex];
Disable SSL
$arrContextOptions=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, ), );
Get the file from the url
$video = file_get_contents($url['url'], false, stream_context_create($arrContextOptions));
Send the video back to front end
return view('convert', [ 'url' => $url['url'], 'quality' => $url['format'], ]);
Expected behavior:
The video gets downloaded
Actual behavior:
I get this error:
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14095126:SSL routines:ssl3_read_n:unexpected eof while reading
The code stops.
Version
The latest version of:
https://github.com/Athlon1600/youtube-downloader/blob/master/src/YouTubeDownloader.php
Additional Information
This code is in the laravel framework, the code here is in the UrlController. This is a local development server, this error also shows up when the firewall is disabled. All the functions used in my code are in the YouTubeDownloader.php file
I had a similar problem.I suspect you are using Xampp-Windows-7.4.5.In that case file_get_contents() function gives the SSL error on laravel.It works on simple(core) php on my side though.
Things You Can Try.
Use Curl instead of file_get_contents().You can create a custom function that would work in the same manner(with SSL enabled) like so.
function file_get_content_curl ($url)
{
// Throw Error if the curl function does'nt exist.
if (!function_exists('curl_init'))
{
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
Then you can call the function like this.
$data = file_get_content_curl($url);
$save = file_put_contents($path, $data);
Disable/Uninstall Skpye.As skpye uses port 80/443(https) ,if you are using apache on port 80 try switching to port 8080 or uninstalling skpye if you dont use it.That might also solve your issue.
Downgrade to Xampp-Windows-7.2.3 if you want to use file_get_contents() function.This also solved the issue for me.
I ran into this issue as well and was able to follow up a little deeper into #Huzaifa99's recommendations.
In my case, I was running a Laravel app with PHP 7.4.5 on Windows. There is apparently an issue with OpenSSL v1.1.1e, possibly just with Windows. Installing the latest build of PHP 7.4.6+ fixed my issues. Specifically, the replacing the file libssl-1_1-x64.dll.
I faced the problem here on Windows 10 with php 7.4.9 and apache v2.4.33.
Although I've updated php to the latest php version (v.7.4.11) the issue did still exist.
It turned out that openssl v1.1.1e which came with apache caused the error. After updating to Apache v2.4.46 with openssl v1.1.1h the problem was solved.
I have same problem on Windows and I found this information:
https://www.php.net/manual/en/function.fopen.php#refsect1-function.fopen-notes
Warning
When using SSL, Microsoft IIS will violate the protocol by closing the connection without sending a close_notify indicator. PHP will report this as "SSL: Fatal Protocol Error" when you reach the end of the data. To work around this, the value of error_reporting should be lowered to a level that does not include warnings. PHP can detect buggy IIS server software when you open the stream using the https:// wrapper and will suppress the warning. When using fsockopen() to create an ssl:// socket, the developer is responsible for detecting and suppressing this warning.
I tried to temporary set error_reporting(0); and it worked for me, I got the response from remote server.
But I should use other solution for my case. Maybe this info will help somebody.
in my case I solved it by copying the libssl-1_1-x64.dll dll from the php folder into the apache bin folder
A less brutal version of #SpecDrum's solution worked for me on PHP 8.1.2. The OpenSSL error is represented in PHP as a warning. So it's enough to ignore warnings (temporarily):
$error_level = error_reporting();
error_reporting($error_level & ~E_WARNING);
I want to read a XML file from a certain link with the following code
$filename = 'http://XXXXX/rss.xml';
$xml = simplexml_load_file($filename);
When I try, I get the following error messages:
wrapper is disabled in the server configuration by allow_url_fopen=0
failed to open stream: no suitable wrapper could be found in
I/O warning : failed to load external entity
Whats the problem? Can it be that the server doesn´t support simplexml_load_file?
When allow_url_fopen is set to 0, you have no permissions to acces URL objects like files. Read official manual for more information.
You can not change this value via .htaccess, so you have to set allow_url_fopen=1 in your php.ini file. If you're using a shared hosting or some kind of it, you should contact hosting technical support and describe them your problem.
This problem seems to have been discussed in the past everywhere on google and here, but I have yet to find a solution.
A very simple fopen gives me a
PHP Warning: fopen(http://www.google.ca): failed to open stream: HTTP request failed!".
The URL I am fetching have no importance because even when I fetch http://www.google.com it doesnt work. The exact same script works on different server. The one failing is Ubuntu 10.04 and PHP 5.3.2. This is not a problem in my script, it's something different in my server or it might be a bug in PHP.
I have tried using a user_agent in php.ini but no success. My allow_url_fopen is set to On.
If you have any ideas, feel free!
It sounds like your configuration isn't allowed to use file functions, which is common these days because of security concerns. If you have the cURL libraries available to you, I would recommend trying those out.
PHP: cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.google.ca/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$file = curl_exec($ch);
curl_close($ch);
echo $file;
Check that your php.ini config is set to allow fopen to open external URL's:
allow_url_fopen "1"
http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen
I'm not at all sure about whether this is the problem or not, but I know in the past I've had problems with opening URLs with fopen, often due to php.ini's allow_url_fopen or other unknown security settings
You may want to try cURL in PHP, which often works for me, you'll find an example really easily by googling that.
Check your phpinfo output - is http present under Registered PHP Streams?
Are you getting "HTTP request failed" without further details? The socket timeout could be expired. This default to 60 seconds. See: http://php.net/manual/en/function.socket-set-timeout.php
I am running the code below in some if/else statements, I have a weird issue in the same file this exact code below works fine, however in another area if it is called I get this error;
Warning: include() [function.include]: URL file-access is disabled in the server configuration in C:\webserver\htdocs\processing\process.friends.php on line 168
Warning: include(http://localhost/index.php) [function.include]: failed to open stream: no suitable wrapper could be found in C:\webserver\htdocs\processing\process.friends.php on line 168
$_SESSION['sess_msg'] = 'Please Enter the Correct Security Code';
$_GET["friendid"] = $friendid;
$_GET["p"] = 'mail.captcha';
$_GET["f"] = 'friend';
include ("index.php");
exit;
And just to clarify I am njot trying to run this code 2 times at the SAME time, it's more like this; Not just like this but you get the point that they are not run at the same time
if(something){
run the code above
}else{
run the code above
}
If it matters, I am currently running a LAMP setup on a windows PC
remove the "http://localhost" part of your code. As a rule of thumb, when you include your own files, you should include them from your file system.
include "./index.php";
Just remove the http://localhost/ part and you'll be okay.
Well, I don't kow the answer to your question, though I do have to ask why you feel the need to include a URL based file?
include('http://whatever.com/'); can be EXTREMELY dangerous.
If you're just trying to output the HTML generated from that, I'd suggest you do something like echo file_get_contents('http://some/url');. If you're trying to include PHP code, use the system path
Are they EXACTLY the same? Could you post both versions of the code?
I can also recommend not doing an include('http://...'); This will make PHP to an HTTP request to your webserver, and grab the result. You might be a bit better off just doing include('index.php');, if this is possible for your setup.
Is allow_url_fopen enabled in php.ini?
I am currently using an image manipulation script to do some work on uploaded images and I'm running into a problem in my dev environment. This same code works on my production server.
The error is:
PHP Warning: imagecreatefromjpeg(): php_network_getaddresses:
getaddrinfo failed: Name or service not known in /path/to/script.php
on line 75
The line of code on 75 is:
$this->img = imagecreatefromjpeg(PHPTHUMB."?src=/".$this->image_path);
which creates an image that is loaded from another made by phpThumb, which is used for further manipulation.
Any ideas on how to solve this? Can anyone shed some light on what the error means?
Thank you,
Edit:
Just as a further bit of insight, if i visit PHPTHUMB . "?src=/" . $this->image_path in my browser, the image loads fine
User agent in php.ini did not solve the problem as indicated here
EDIT (SOLUTION): I had to add the INTERNAL 192.168.204.XXX IP into the hosts file, so that http://dev.mysite.com resolved correctly. Trying both 127.0.0.1 and the external IP yielded no result, but the internal works perfectly. Thanks for everyone's efforts,
I'm totally not sure about the cause of that error, but this is my best guess.
There is a particular PHP Setting which enables you to treat URLs as files. Normally imagecreatefromjpeg accepts a filename, I think. Since you are passing a URL, you need to make sure the particular setting is enabled. I believe you can find more info about it here: http://us2.php.net/file
filename
Path to the file.
Tip
A URL can be used as a filename with this function if the fopen
wrappers have been enabled. See
fopen() for more details on how to
specify the filename and List of
Supported Protocols/Wrappers for a
list of supported URL protocols.
Fopen wrappers: http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen
Your dev environment may not be setup with this, but your production environment could be.
Edit
This page lists your error:
http://bugs.php.net/bug.php?id=11058
and mentions that a possible fix is by modifying your hosts file to explicitly include the ip/dns of the server you're accessing.
i tryed to reconfigure my named
configuration, without any result, to
fix this. the problem was solved by
adding the following line to my
/etc/hosts:
194.97.55.147 mx.freenet.de
Maybe you can try this?
did you also check that allow_url_fopen is set to On in php.ini?
I saw that they did mention that in the article you referred to in your post.
EDIT: Also, what OS and what PHP version are you running?
Just read this on php.net: "On Windows versions prior to PHP 4.3.0, the following functions do not support remote file accessing: include(), include_once(), require(), require_once() and the imagecreatefromXXX functions in the GD Functions extension."
EDIT2:
I just read what was written in the comments, your allow_url_fopen is set to On, sorry about that.
But OS, PHP version and phpinfo() would help in finding the problem.
The error message suggests something is wrong at a networking level. Thus, if possible, bypass that. Try using the path to the thumbnail generator, instead of a network address.
If that's not an option, try something that will give you more granular error messages. I suggest CURL. At the very least, it should yield a more informative error message.
The simple fact that this is failing is because on your webserver, your DNS resolution is broken.
If you have SSH access to your server, try the following command
dig hostname
where hostname is the host name from PHPTHUMB
This will probably fail.
Assuming that you're using Linux, my suggestion would be to edit your /etc/resolv.conf (as root)
and add the following line before any other lines beginning with "nameserver"
nameserver 4.2.2.2
This should hopefully fix things, though you may have to restart apache (or whatever webserver you're using)!
The issue here is that php fails to resolve the url that you provide as PHPTHUMB as stated in this bug report on php.net. This possibly means that it's the fault of the operating system/web server, in which case you can enter the ip address of the server you are connecting to into your hosts file manually.