It looks like you're new here. If you want to get involved, click one of these buttons!
function is_animated_gif( $filename )
{
$raw = file_get_contents( $filename );
$offset = 0;
$frames = 0;
while ($frames < 2)
{
$where1 = strpos($raw, \"\x00\x21\xF9\x04\", $offset);
if ( $where1 === false )
{
break;
}
else
{
$offset = $where1 + 1;
$where2 = strpos( $raw, \"\x00\x2C\", $offset );
if ( $where2 === false )
{
break;
}
else
{
if ( $where1 + 8 == $where2 )
{
$frames ++;
}
$offset = $where2 + 1;
}
}
}
return $frames > 1;
}
<?php
session_start();
include_once \"../../conn/conn.inc.php\";
$name=$_SESSION['uname'];
$des=$_GET['description'];
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
$extension = end(explode('.', $targetFile));
$type = \".\".strtolower($extension);
$filename= $_FILES['Filedata']['name'];
// Uncomment the following line if you want to make the directory if it doesn't exist
// mkdir(str_replace('//','/',$targetPath), 0755, true);
move_uploaded_file($tempFile,$targetFile);
$sql = \"INSERT INTO `login_reg_love`.`up_file` (`filename`, `filepath`, `filetype`, `upauthor`,`descr`, `uptime`) VALUES ('\".$filename.\"', '\".$targetFile.\"', '\".$type.\"', '\".$name.\"','\".$des.\"', NOW())\";
$num=$conne->uidRst($sql);
/*
if($num==1){
echo $up_path;
}else{
echo \"上传失败\";
}
*/
}
switch ($_FILES['Filedata']['error'])
{
case 0:
//$msg = \"No Error\"; comment this out if you don't want a message to appear on success.
break;
case 1:
$msg = \"The file is bigger than this PHP installation allows\";
break;
case 2:
$msg = \"The file is bigger than this form allows\";
break;
case 3:
$msg = \"Only part of the file was uploaded\";
break;
case 4:
$msg = \"No file was uploaded\";
break;
case 6:
$msg = \"Missing a temporary folder\";
break;
case 7:
$msg = \"Failed to write file to disk\";
break;
case 8:
$msg = \"File upload stopped by extension\";
break;
default:
$msg = \"unknown error \".$_FILES['Filedata']['error'];
break;
}
If ($msg)
$stringData = \"Error: \".$_FILES['Filedata']['error'].\" Error Info: \".$msg;
else
$stringData = \"1\"; // This is required for onComplete to fire on Mac OSX
echo $stringData;
$imgsize = getimagesize($targetFile);
switch(strtolower(substr($targetFile, -3))){
case \"jpg\":
$image = imagecreatefromjpeg($targetFile);
break;
case \"png\":
$image = imagecreatefrompng($targetFile);
break;
case \"gif\":
$image = imagecreatefromgif($targetFile);
break;
default:
exit;
break;
}
$width = 80; //New width of image
$height = $imgsize[1]/$imgsize[0]*$width; //This maintains proportions
$src_w = $imgsize[0];
$src_h = $imgsize[1];
$picture = imagecreatetruecolor($width, $height);
imagealphablending($picture, false);
imagesavealpha($picture, true);
$bool = imagecopyresampled($picture, $image, 0, 0, 0, 0, $width, $height, $src_w, $src_h);
if($bool){
switch(strtolower(substr($targetFile, -3))){
case \"jpg\":
// header(\"Content-Type: image/jpeg\");
$bool2 = imagejpeg($picture,$targetPath.\"Thumbs/\".$_FILES['Filedata']['name'],80);
break;
case \"png\":
// header(\"Content-Type: image/png\");
imagepng($picture,$targetPath.\"Thumbs/\".$_FILES['Filedata']['name']);
break;
case \"gif\":
// header(\"Content-Type: image/gif\");
imagegif($picture,$targetPath.\"Thumbs/\".$_FILES['Filedata']['name']);
break;
}
}
imagedestroy($picture);
imagedestroy($image);
echo '1';
?>
<div id=\"ff\">
<div><img id=\"thumbs\"></div>
<div>select images:</div>
<div><input type=\"file\" id=\"fileInput\" name=\"fileInput\" /></div>
<button type=\"button\" id=\"fileUploadStart\">fileUploadStart</button>
<button type=\"button\" onclick=\"$('#fileInput').fileUploadClearQueue();\">Clear queue</button>
</div>
$sourceFile = $_GET['file'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . '/uploadify/' . $_GET['folder'] . '/';
$targetPath = str_replace('//','/',$targetPath);
$localSourceFile = $targetPath . $sourceFile;
$thumbUrl = $targetPath.\"Thumb_\".$sourceFile;
$imgsize = getimagesize($localSourceFile);
$image = imagecreatefromjpeg($localSourceFile);
$width = 70; //New width of image
$height = $imgsize[1]/$imgsize[0]*$width; //This maintains proportions
$src_w = $imgsize[0];
$src_h = $imgsize[1];
$picture = imagecreatetruecolor($width, $height);
imagealphablending($picture, false);
imagesavealpha($picture, true);
$bool = imagecopyresampled($picture, $image, 0, 0, 0, 0, $width, $height, $src_w, $src_h);
if($bool){
header(\"Content-Type: image/jpeg\");
$bool2 = imagejpeg($picture,$thumbUrl,80);
}
imagedestroy($picture);
imagedestroy($image);
header(\"Content-Type: image/jpeg\");
echo file_get_contents($thumbUrl);
function fct_redim_image($Wmax, $Hmax, $rep_Dst, $img_Dst, $rep_Src, $img_Src) {
// ------------------------------------------------------------------
$condition = 0;
// If some parameter are empty :
if ($rep_Dst == '') { $rep_Dst = $rep_Src; } // (same folder)
if ($img_Dst == '') { $img_Dst = $img_Src; } // (same name)
if ($Wmax == '') { $Wmax = 0; }
if ($Hmax == '') { $Hmax = 0; }
// ------------------------------------------------------------------
// if file exist in the folder, go on...
if (file_exists($rep_Src.$img_Src) && ($Wmax!=0 || $Hmax!=0)) {
// ----------------------------------------------------------------
// accepted extension files :
$ExtfichierOK = '\" jpg jpeg png\"';
// extension
$tabimage = explode('.',$img_Src);
$extension = $tabimage[sizeof($tabimage)-1]; // last part
$extension = strtolower($extension);
// ----------------------------------------------------------------
// extension OK ? go on ...
if (strpos($ExtfichierOK,$extension) != '') {
// -------------------------------------------------------------
// taking dimension of the original file
$size = getimagesize($rep_Src.$img_Src);
$W_Src = $size[0]; // largeur
$H_Src = $size[1]; // hauteur
// -------------------------------------------------------------
// some condition of resizing
// -------------------------------------------------------------
// A- WIDTH and Height max fix
if ($Wmax != 0 && $Hmax != 0) {
$ratiox = $W_Src / $Wmax; // ratio in width
$ratioy = $H_Src / $Hmax; // ratio in height
$ratio = max($ratiox,$ratioy); //the biggest
$W = $W_Src/$ratio;
$H = $H_Src/$ratio;
$condition = ($W_Src>$W) || ($W_Src>$H); // 1 if true
} // -------------------------------------------------------------
// B- WIDTH max fix
if ($Hmax != 0 && $Wmax == 0) {
$H = $Hmax;
$W = $H * ($W_Src / $H_Src);
$condition = $H_Src > $Hmax; // 1 if true
}
// -------------------------------------------------------------
// C- HEIGHT max fix
if ($Wmax != 0 && $Hmax == 0) {
$W = $Wmax;
$H = $W * ($H_Src / $W_Src);
$condition = $W_Src > $Wmax; // 1 if true
}
// -------------------------------------------------------------
// Resize if $condition is true
// -------------------------------------------------------------
if ($condition == 1) {
switch($extension) {
case 'jpg':
case 'jpeg':
$Ress_Src = imagecreatefromjpeg($rep_Src.$img_Src);
$Ress_Dst = ImageCreateTrueColor($W,$H);
break;
case 'png':
$Ress_Src = imagecreatefrompng($rep_Src.$img_Src);
$Ress_Dst = ImageCreateTrueColor($W,$H);
imagesavealpha($Ress_Dst, true);
$trans_color = imagecolorallocatealpha($Ress_Dst, 0, 0, 0, 127);
imagefill($Ress_Dst, 0, 0, $trans_color);
break;
}
// ----------------------------------------------------------
//
ImageCopyResampled($Ress_Dst, $Ress_Src, 0, 0, 0, 0, $W, $H, $W_Src, $H_Src);
// ----------------------------------------------------------
// Save in the folder
switch ($extension) {
case 'jpg':
case 'jpeg':
ImageJpeg ($Ress_Dst, $rep_Dst.$img_Dst);
break;
case 'png':
imagepng ($Ress_Dst, $rep_Dst.$img_Dst);
break;
}
// ----------------------------------------------------------
//
imagedestroy ($Ress_Src);
imagedestroy ($Ress_Dst);
}
// -------------------------------------------------------------
}
}
// ---------------------------------------------------------------------------------------------------------------------
}
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
// $fileTypes = str_replace('*.','',$_REQUEST['fileext']);
// $fileTypes = str_replace(';','|',$fileTypes);
// $typesArray = split('\|',$fileTypes);
// $fileParts = pathinfo($_FILES['Filedata']['name']);
// if (in_array($fileParts['extension'],$typesArray)) {
// Uncomment the following line if you want to make the directory if it doesn't exist
// mkdir(str_replace('//','/',$targetPath), 0755, true);
move_uploaded_file($tempFile,$targetFile);
}
$img_Src = $_FILES['Filedata']['name'];
$rep_Src = $targetPath;
$rep_Dst = $targetPath.\"miniatures/\";
$img_Dst = 'pict-'.$img_Src;
$RedimOK = fct_redim_image(200, 200, $rep_Dst, $img_Dst, $rep_Src, $img_Src);
echo \"1\";
// } else {
// echo 'Invalid file type.';
// }
ImageJpeg ($Ress_Dst, $rep_Dst.$img_Dst);
ImageJpeg ($Ress_Dst, $rep_Dst.$img_Dst, 100);
RonnieSan said:For those who don't need thumbnails saved to the server, there is a great script for creating thumbs on the fly with caching.
http://www.darrenhoyt.com/2008/04/02/ti ... -released/
