I have a valid link that goes to a picture located on my web server. It is a simple jpg image, I can copy and paste this link into my web browser and it loads fine. The issue comes in when I try to call a few php functions on the image... such as getimagesize or fopen... they both return 404 errors even though the image is there. Does anyone know that could be causing this?
Thank you for your time.
Are you using a local path? Or a full URL?
If full, do you have the protocol (e.g. "http") in front of the address? Not having the protocol might make PHP look for the URL in the local scope, which results in the image being not found.
EDIT:
Have you made sure the allow_url_fopen and allow_url_include are enabled on the new server?
Is allow_url_fopen enabled? Your installation may not allow opening files by URL.
var_dump( ini_get('allow_url_fopen') );
What happens when you look in your webserver's error log? This will tell you why the URL is returning a 404.
Related
We are getting plagued with this which started in April on working server. Everything was fine with our application until the customer reported that PDFs were no longer displaying the images.
Our PDF is generated via a HTML render first. When the HTML render is displayed the Image shows correctly. Also the image shows correctly if the image URL as noted in the mPDF is copied and pasted into a new tab.
However... If we load the image from a DIFFERENT DOMAIN then the image is rendered correctly. loading the image via absolute path, relative path or URL path all result in this error:
mPDF error: IMAGE Error (http://www.aibsonline.co.uk/logo.gif): Could not find image file
But, as you will see the logo url works when pasted. File permissions have been tested (which is why it is in the root) as standard and up to 777. Server is a Linux server in both cases we have seen so far.
HTML Code that renders the logo:
<div id="logo_wrapper" class="left">
<img width="107" height="76" src="<?php echo base_url('logo.gif'); ?>" />
</div>
At a real loss with this one and it is beginning to affect more and more clients.
Any help gratefully received.
UPDATE
The image renders if the rendering code and the image are in the same directory and we do NOT use an absolute path, eg.
<img width="107" height="76" src="logo.gif" />
I ran across this issue today. My problem was that the domain name I was using didn't resolve back to the server when accessed from the server. I added an entry to the hosts file on the server, and images started showing.
Your equivalent hosts file entry of what fixed my problem would be:
127.0.0.1 www.aibsonline.co.uk
Or otherwise ensure that www.aibsonline.co.uk resolves to your server in the DNS that your server uses.
It appears that mPDF accesses images as a cURL web client, so DNS on the server needs to be configured correctly to refer back to itself.
I had a similar issue and I solve by following:
1.Check if gd library is installed and enable in your php ini file. If not install gd library.
2.Turn on debug variable
$mpdf = new mPDF();
$mpdf->showImageErrors = true;
3.Try inter-changing absolute/relative path for the image
<img src="http://someDomain/directory/image.jpg">
<img src="./directory/image.jpg">
Hope this helps.
With same issue, I found that get_headers() returns:
"HTTP/1.1 412 Precondition Failed"
Provider says this was due to web firewall, because the request was badly formed and the user_agent not set.
An ini_set('user_agent', 'Mozilla/5.0'); solved the problem.
In a WordPress plugin using mpdf, mpdf doesn't use WordPress http classes and doesn't set user_agent. I solved this by adding in mu-plugins:
global $wp_version;
ini_set('user_agent',apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ));
I tried all other answers here but for me, only adding
$mpdf->curlAllowUnsafeSslRequests = true;
fixed the issue.
I was running into the same issue. mPDF was running DOG SLOW and would end up just displaying a "Cannot find image file" error. After
checking to make sure the image is actually there
checking the permissions on the file
checking all of the error logs on the server
combing through the documentation on mPDF
I found that the image file in question was corrupted somehow. I downloaded the image to my local computer, opened it up with an image editor (Paint.NET in this case), re-saved it as a .gif file and uploaded it to the server again. That seemed to fix it. Your mileage my vary.
Also, for what its worth, I had to use images/image.gif instead of the file path /images/image.gif.
Just make sure that you have image related functions in your PDF class file. Like parsejpg, parsepng, parsegif etc...
I have password protected server (.htaccess / .passwd) and after some research I understand that mPDF using HTTP to get the images, but server blocks the images from the public because of password protection.
After removing password protection I had ssl certificate issue, and I enable usafe requests and it starts working
$mpdf->curlAllowUnsafeSslRequests = true;
Also you can always enable debug modes and follow the error messages
$mpdf->showImageErrors = true;
$mpdf->debug = true;
I tried to use Google Doc Embedder by using this code
[gview file="http://localhost/wordpress/wp-content/uploads/2013/07/list.pdf"]
but this error keeps on showing up..
Sorry, we were unable to find the document at the original source. Verify that the document still exists.
You can also try to download the original document by clicking here.
I checked in the directory/path to verify and its still there. So what is the reason that this error keeps on showing up?
Google Docs doesn't have access to your local machine. It will need to be on publicly accessible web server for that to work.
Your file path is wrong. You are pointing to localhost for your server. This is something running on your machine only so google reader would not be able to point to a file on your machine.
You should upload your file to a public server.
You can try even
<iframe src="http://localhost:8080/pdf">
I think there are plugins for iframe in wordpress ,Try it out..
In my Wordpress I use this plugin for Google Docs to embed .pdf
DirtySuds - Embed PDF
Then in the post use this:
[embed width="620" height="600"]http://site.com/file.pdf[/embed]
edit:
You will need live host to upload your .pdf files there.
I am using timthumb to present images inside a Wordpress theme. It works fine when showing images from the same server but as soon as I try to load external images (in this case youtube thumbnails) it returns a 404 as if the script itself couldn't be found. The script is there though, if I load local images it behaves as expected. I have t set to allow external images, and specifically those from img.youtube.com
The strange thing is the exact same theme works as expected on my localhost and the external images show up fine, so I'm guessing it's something wrong on the hosting. Any suggestions as to what this may be?
IS your host allows to load images from external source. means out side of server ? This may be a problem.
HostGator do not allow absolute paths to use with TimThumb (even if it's hosted in your own account) as described in this article: http://support.hostgator.com/articles/specialized-help/technical/timthumb-basics.
To fix the absolute path issue, you'll would need to hack your theme functions to strip off your domain from the image path:
$url = "/path/to/timthumb.php?src=" . str_replace(site_url(), '', $path_to_image);
This used to work and now it doesn't on my server. This is kind of a last ditch effort to try to figure out what is going wrong here. I'm simply trying to copy a profile image from Facebook to a folder on my server. Here's the only code I'm using:
file_put_contents("..//images/artist_pictures/artist_216.jpg", file_get_contents("http://graph.facebook.com/553451657/picture?type=large"));
After that runs I get a 0kb image file called artist_216.jpg. Any ideas?
I'm not too good with PHP, but I know that the picture URL you're using is a redirect to another file on Facebook's CDN. I'm guessing you need to somehow resolve the actual location and pull the contents of the redirect.
You need to adjust your php.ini file.
Change allow_url_fopen = Off to allow_url_fopen = on.
In my site, I give an option to upload images with .jpg and .JPG extension. They both work and I can see both on the server itself.
When I try to see in the browser the photos with the .jpg extension by calling them name.jpg, they work. When I call to the othername.JPG (which is called that way on the server) it does not work and does not show it. othername.jpg does not work too.
I suppose your web server is not configured to send the Content-Type: image/jpeg HTTP header for such files. It's possible that some browsers refuse to display them as pictures if the MIME type does not match. If you happen to be using Apache, you can fix it yourself in an .htaccess file:
AddType image/jpeg .JPG
You should also consider that you cannot count of URLs being case-insensitive: FOO can equal foo... or not. Use always the exact case and save yourself future problems.
Edit:
Before misconfiguring random stuff, you can follow this checklist and see what fails exactly:
Is the URL valid? Foo.jpg is not the same as foo.jpg.
Does the browser receive the file? Firebug should tell you.
What's the HTTP response code? Firebug should tell you.
What's the Content-Type header? Firebug should tell you.
Common status codes:
404: the file could not be found. Most likely, your URL is wrong.
403: you are not authorised to see the file. It can be a permissions issue.
500: generic server error code. You should open your hosting service control panel and have a look at the error log.
Your using linux/apache right? make the filenames lowercase. its the default for them to be accessed on linux.
try to check the contents of that file, maybe your script is messing up JPG uploaded files.
if that doesn't work maybe it's from your system .. an .htaccess
Look in error logs for anything that is related to this file.