调整存储在根目录之外的映像的大小

时间:2015-03-27 19:20:31

标签: php

为了安全起见,我将所有图像存储在根目录外的文件夹中。但是当我在网页上显示图像时,我无法调整图像大小。图像以完整尺寸显示。 如何调整图像大小以便在网页中显示。

<?php
// The path where the images are stored.
$imgLocation = '/Applications/XAMPP/im/';


$imgName = 'tesla.jpg';

// Construct the actual image path.
$imgPath = $imgLocation . $imgName;

// Make sure the file exists
if(!file_exists($imgPath) || !is_file($imgPath)) {
header('HTTP/1.0 404 Not Found');
die('The file does not exist');
}

// Make sure the file is an image
$imgData = getimagesize($imgPath);
if(!$imgData) {
header('HTTP/1.0 403 Forbidden');
die('The file you requested is not an image.');
}

// Set the appropriate content-type
// and provide the content-length.
header('Content-type: ' . $imgData['mime']);
header('Content-length: ' . filesize($imgPath));

// Print the image data
readfile($imgPath);

?>

0 个答案:

没有答案