- 你犯了一些小错误
- header('Content-type: image/jpeg') 应该在图像内容之前
- 检查你的文件夹设置喊它是
../
或../../
所以你是php代码:
$file_name = (int)$routes[2];
$file = '../images/'.$file_name;
$sql = "SELECT i.image_filetype as filetype, i.image_type as type, i.image_key "
. "FROM images i "
. "WHERE i.image_deleted IS NULL "
. "AND i.image_id = :filename LIMIT 1";
$results = $db_connect->prepare($sql);
$results->bindParam(':filename', $file_name, PDO::PARAM_INT);
$results->execute();
$db_image = $results->fetchAll(PDO::FETCH_ASSOC);
foreach($db_image as $output){
// PROFILE PICTURE
if($output['type'] === '1'){
$path = $file.'.'.$output['filetype'];
if(file_exists($path)){
header('Content-type: image/jpeg');
echo file_get_contents($path);
exit;
}else{$error_code = 4;}
}
}
die('1');
更新代码:
不知道你做错了什么,但下面的代码对我有用。所以请提供结果细节。godaddy2.jpg
我在父images
文件夹中的图像文件 ID 。
<?php
// ROUTES[2] IS = IMAGE_ID + UNIQID
// EXAMPLE: 23
//$file_name = (int)$routes[2];
$file_name = 'godaddy2';
//$file = '/home/husliste/images/'.$file_name;
$file = '../images/'.$file_name;
//
//$sql = "SELECT i.image_filetype as filetype, i.image_type as type, i.image_key "
// . "FROM images i "
// . "WHERE i.image_deleted IS NULL "
// . "AND i.image_id = :filename LIMIT 1";
//$results = $db_connect->prepare($sql);
//$results->bindParam(':filename', $file_name, PDO::PARAM_INT);
//$results->execute();
//$db_image = $results->fetchAll(PDO::FETCH_ASSOC);
$db_image[] = [
'filetype' =>'jpg',
'type' =>'1',
];
function checkPlanAccess($a){
return true;
}
foreach($db_image as $output){
if($output['type']){
// CREATE HEADER
switch($output['filetype']){
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpeg";break;
default:
}
header('Content-type: '.$ctype);
// CREATE FILE PATH
$file_path = $file.'.'.$output['filetype'];
// =========================================== //
// PLAN
if($output['type'] === '1'){
if(checkPlanAccess($output['image_key'])){
if(file_exists($file_path)){
echo file_get_contents($file_path);
}else{$error_code = 4;}
}else{$error_code = 4;}
}
// PROFILE PICTURE
elseif($output['type'] === '2' && $check_session){
if(file_exists($file_path)){
$image = file_get_contents($file_path);
echo $image;
}else{$error_code = 4;}
}
// COMPANY LOGO
elseif($output['type'] === '3' && $check_session){
if(file_exists($file_path)){
echo file_get_contents($file_path);
}else{$error_code = 4;}
}
// CUSTOMER LOGO
elseif($output['type'] === '4'){
if(checkCustomerAccess($output['image_key'])){
if(file_exists($file_path)){
echo file_get_contents($file_path);
}else{$error_code = 4;}
}else{$error_code = 4;}
}
// CUSTOMER PROJECT IMAGES
elseif($output['type'] === '5'){
if(checkCustomerProjectAccess($output['image_key'])){
if(file_exists($file_path)){
echo file_get_contents($file_path);
}else{$error_code = 4;}
}else{$error_code = 4;}
}
// SUPPLIER LOGO
elseif($output['type'] === '6'){
if(checkSupplierAccess($output['image_key'])){
if(file_exists($file_path)){
echo file_get_contents($file_path);
}else{$error_code = 4;}
}else{$error_code = 4;}
}else{
$error_code = 4;
}
}else{
$error_code = 4;
}
}
die('1');
?>