class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
I use a script to show images. I can upload images fine but when I try to show them I get an error message. I don't do any processing to the image. I just need to pull from the server and show on a web page.
The code to output local image
$img = new upload($imgurl);
header('Content-type: ' . $img->file_src_mime);
echo $img->Process();
Log system information - class version : 0.29 - operating system : FreeBSD - PHP version : 4.4.9 - GD version : 2.0.28 - supported image types : png jpg gif bmp - open_basedir : no restriction - language : en_GB source is a local file /home/lifespa/uploads/pics/11_svclogo_226116.jpg - local file name OK determining MIME type - Checking MIME type with Fileinfo PECL extension Fileinfo PECL extension not available - Checking MIME type with UNIX file() command MIME type detected as image/jpeg by UNIX file() command - MIME validated as image/jpeg source variables - You can use all these before calling process() file_src_name : 11_svclogo_226116.jpg file_src_name_body : 11_svclogo_226116 file_src_name_ext : jpg file_src_pathname : /home/lifespa/uploads/pics/11_svclogo_226116.jpg file_src_mime : image/jpeg file_src_size : 4909 (max= 52428800) file_src_error : 0 - source file is an image image_src_x : 150 image_src_y : 137 image_src_pixels : 20550 image_src_type : jpg image_src_bits : 8
Please let me know what I can do to get the images to show.
I tried with your three lines of code, and it worked, the image got output to the browser. It also works when processing the image, for instance resizing it.Reply
When I look at the code in Firefox here is the message I get when I try to view the pic:
The image “view-source:https://thedomain.com/~lifespa/demo/getfile.php?t=svc&id=6” cannot be displayed, because it contains errors.
If I call the picture directly it shows as it should.
While trying to troubleshoot I turned off the header output of the image mime type and was able to see the code from the picture print. But, as soon as I add header('Content-type: ' . $img->file_src_mime); I get the error message above.
To get the output from the object after local image upload I did this:
I uploaded a png file using this class then tried to access it with both of your code examples and got this error each time: The image “view-source:https://mydomain.com/~lifespa/demo/getfile.php?t=svc&id=7” cannot be displayed, because it contains errors.
I think your server has a problem when sending headers.
Here are my headers when outputing an image: HTTP/1.1 200 OK Date: Wed, 03 Mar 2010 20:44:10 GMT Server: Apache...... X-Powered-By: PHP/5....... Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: image/png
As you can see, my Content-Type is image/png when yours is text/html. In fact, if I output the image without sending the headers, I have text/html too. So it looks to me like your PHP may not be outputing the headers properly.
Besides, it is very possible that you output something else than the image (and its headers) before. If, in your script, you echo some text for instance before outputing the image, then you will have the message The image “...” cannot be displayed, because it contains errors..
So I recommend you try with a very simple script to output an image. Check that you don't have anything (HTML...) before the PHP opening tag in your script, and that your script doesn't output anything before the image headers.
With this code, you should see image/png in the HTTP headers, and then your image should display. If not, it may be a problem with your PHP installation, or your Apache server. Try it on another setup to make sure that your code works, or doesn't.Reply
I use a script to show images. I can upload images fine but when I try to show them I get an error message. I don't do any processing to the image. I just need to pull from the server and show on a web page.
The code to output local image
Log
system information
- class version : 0.29
- operating system : FreeBSD
- PHP version : 4.4.9
- GD version : 2.0.28
- supported image types : png jpg gif bmp
- open_basedir : no restriction
- language : en_GB
source is a local file /home/lifespa/uploads/pics/11_svclogo_226116.jpg
- local file name OK
determining MIME type
- Checking MIME type with Fileinfo PECL extension
Fileinfo PECL extension not available
- Checking MIME type with UNIX file() command
MIME type detected as image/jpeg by UNIX file() command
- MIME validated as image/jpeg
source variables
- You can use all these before calling process()
file_src_name : 11_svclogo_226116.jpg
file_src_name_body : 11_svclogo_226116
file_src_name_ext : jpg
file_src_pathname : /home/lifespa/uploads/pics/11_svclogo_226116.jpg
file_src_mime : image/jpeg
file_src_size : 4909 (max= 52428800)
file_src_error : 0
- source file is an image
image_src_x : 150
image_src_y : 137
image_src_pixels : 20550
image_src_type : jpg
image_src_bits : 8
Please let me know what I can do to get the images to show.
Thanks
Kim Carr
I tried with your three lines of code, and it worked, the image got output to the browser. It also works when processing the image, for instance resizing it.
The image “view-source:https://thedomain.com/~lifespa/demo/getfile.php?t=svc&id=6” cannot be displayed, because it contains errors.
If I call the picture directly it shows as it should.
While trying to troubleshoot I turned off the header output of the image mime type and was able to see the code from the picture print. But, as soon as I add header('Content-type: ' . $img->file_src_mime); I get the error message above.
To get the output from the object after local image upload I did this:
The output is below:
It seems that you have a problem of headers. Check what headers are being sent to Firefox (you can use LiveHTTPHeaders for that).
You can also try to first output an image to the browser without using the class itself. Code such as (here with PNG images):
or
Thank you for helping with this.
I uploaded a png file using this class then tried to access it with both of your code examples and got this error each time: The image “view-source:https://mydomain.com/~lifespa/demo/getfile.php?t=svc&id=7” cannot be displayed, because it contains errors.
Here's the output from LiveHTTPHeaders.
https://mydomain.com/~lifespa/demo/getfile.php?t=svc&id=7
GET /~lifespa/demo/getfile.php?t=svc&id=7 HTTP/1.1
Host: mydomain.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729)
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: https://mydomain.com/~lifespa/demo/index.php?p=service&action=edit&sid=7
Cookie: __utma=63748150.1862303144.1225142372.1260905107.1265309473.21; __utmz=63748150.1256751018.18.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=9b9bf89c40caccf4f6f7f21811be1fa7
HTTP/1.1 200 OK
Date: Wed, 03 Mar 2010 19:37:43 GMT
Server: Apache
X-Powered-By: PHP/4.4.9
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
Here are my headers when outputing an image:
HTTP/1.1 200 OK
Date: Wed, 03 Mar 2010 20:44:10 GMT
Server: Apache......
X-Powered-By: PHP/5.......
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: image/png
As you can see, my Content-Type is image/png when yours is text/html. In fact, if I output the image without sending the headers, I have text/html too. So it looks to me like your PHP may not be outputing the headers properly.
Besides, it is very possible that you output something else than the image (and its headers) before. If, in your script, you echo some text for instance before outputing the image, then you will have the message The image “...” cannot be displayed, because it contains errors..
So I recommend you try with a very simple script to output an image. Check that you don't have anything (HTML...) before the PHP opening tag in your script, and that your script doesn't output anything before the image headers.
Here is the code I use to try it out:
With this code, you should see image/png in the HTTP headers, and then your image should display. If not, it may be a problem with your PHP installation, or your Apache server. Try it on another setup to make sure that your code works, or doesn't.
Thank you so much for your help and for creating this class. Turns out the the problem was a PICNIC! Problem In Chair Not In Computer.
Following your advice I tracked the problem down to two blank lines at the end of my defines file.
Thanks Again
Kim Carr