如何在運行時預覽圖像?我有上傳腳本和重新大小功能。但圖像沒有在運行時顯示。我不想保存iamge.Just調整大小和顯示在運行time.Image必須從內存中不顯示從目錄中。我是想這樣的事情:在運行時調整圖像大小php
if ($_FILES['myfile']['error'] == 0)
{
$theImageToResize=$_FILES['myfile']['name'];
$afterResize=Resize($theImageToResize);
echo $theImageToResize.'---->image after resize';
}
[只想從目錄中memory.Not顯示圖片]
服務器端代碼:
$savefolder = 'images'; //upload dir
$max_size = 35000; //in bytes
// image types
$allowtype = array('bmp', 'gif', 'jpg', 'jpeg', 'gif', 'png');
$res = '';
// if is received a valid file
if (isset ($_FILES['myfile'])) {
$type = end(explode(".", strtolower($_FILES['myfile']['name'])));
if (in_array($type, $allowtype)) {
if ($_FILES['myfile']['size']<=$max_size*1000) {
if ($_FILES['myfile']['error'] == 0) {
$thefile = $savefolder . "/" . $_FILES['myfile']['name'];
$theImageToResize=$_FILES['myfile']['name'];
header('Content-type: image/jpeg');
$res = '<img src="'.$theImageToResize.'" />';
}
}
else { $res = 'The file <b>'. $_FILES['myfile']['name']. '</b> exceeds max Size <i>'. $max_size. 'KB</i>'; }
}
else { $res = 'The file <b>'. $_FILES['myfile']['name']. '</b> has not an allowed File Tyle..'; }
}
$res = urlencode($res);
echo '<body onload="parent.doneloading(\''.$res.'\')"></body>';
如果我是你,我會用javascript做到這一點。 – markus 2012-02-29 08:25:22