I'm trying to display the image if has one from a URL, like verImagem.php?img=screenshot-imgname.png
. If imgname.png
exists then should see the image with in a content type.
The code is working in Windows, but not on Ubuntu - tryed look at nginx config, Cloudflare, also checked if the GD Library is installed, couldn't find the problem.
Currently I'm using PHP 7.0 on Ubuntu Server 14.04.
When I try access the image it returns The image "link" cannot be displayed because it contains errors.
This script below is the one that I'm trying to display the image.
<?php
$urlFolder = "./images/screenshots/";
$requestImage = $_GET['img'];
$imageName = str_substract("screenshot-", $requestImage);
$imgpath = $urlFolder . $imageName;
$fp = fopen($imgpath, 'rb');
$ext = getimagesize($imgpath);
if ($ext['mime'] == "image/png")
header("Content-Type: image/png");
elseif ($ext['mime'] == "image/jpeg")
header('Content-Type: image/jpeg');
elseif ($ext['mime'] == "image/gif")
header('Content-Type: image/gif');
header("Content-Length: " . filesize($imgpath));
fpassthru($fp);
exit;
My nginx config for the port 80. I replaced a few things with "*".
server {
listen 80 default_server;
root /home/www;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name **********;;
location / {
# First attempt to serve request as file, then as
# directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location /.well-known/acme-challenge {
root /home/www/;
}
listen 443 ssl default_server;
ssl_certificate **********;
ssl_certificate_key **********;;
location ~* \.(jpg|jpeg|gif|png|bmp)$ {
try_files $uri $uri/ /index.php$is_args$args;
add_header Cache-Control public;
add_header Cache-Control must-revalidate;
expires 7d;
}
location ~* \.(ico|css|js)$ {
expires 365d;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_read_timeout 120;
}
location ~ /\.ht {
deny all;
}
}