Smart Image Processor PHP 2 Support Product Page
Answered
Advance Multi uploader and SIP storage in a database !
Asked 31 Dec 2011 02:36:28
1
has this question
31 Dec 2011 02:36:28 Loïc Mabire posted:
Hi everybody,I spent a good part of last night looking for an issue to my problem, hope you'll could help me in the good way
All the the code bellow
I'm programming a backoffice for my customers and one of the module should help them to create some album of their pictures they'll have to upload.
So I look for DMX extensions and I bought PHP uploader + SIP + PPU add on + Multi uploader.
Here is my problem :
I would like to upload several picture a time and store the filename in the database. I use Multi uploader in this way and it works fine.
But at the same moment i want to resize pictures in 2 ways :
- first creating thumbnails
- resizing my just uploaded pictures
---------------- CODE --------------
// Connecting to database (it works !)
<?php require_once('Connections/marscoiff.php'); ?>
<?php require_once('ScriptLibrary/incPureUpload.php'); ?>
<?php require_once('ScriptLibrary/cGraphicMediator.php'); ?>
// Modifiy MEMORY_LIMIT
<?php ini_set('memory_limit','256M');?>
<?php
// Retrieving last album ID (it works !)
mysql_select_db($database_marscoiff, $marscoiff);
$query_Dernier_album = "SELECT * FROM album ORDER BY alb_id DESC";
$Dernier_album = mysql_query($query_Dernier_album, $marscoiff) or die(mysql_error());
$row_Dernier_album = mysql_fetch_assoc($Dernier_album);
$totalRows_Dernier_album = mysql_num_rows($Dernier_album);
// CREATING DIRECTORY to store my pictures (it works !)
$dir = opendir("../userfiles/images/album" ;
$rep="userfiles/images/album/" ;
$rep .= $row_Dernier_album['alb_id'] ;
@mkdir($rep,0777,true);
// Preparing a variable for the Thumb (it works !)
$thumb=$rep ."/thumb_";
closedir($dir);
?>
<?php
// Pure PHP Upload 2.1.12
$ppu = new pureFileUpload();
// CHANGING the upload directory (it works !)
$ppu->path = $rep;
$ppu->extensions = "GIF,JPG,JPEG,BMP,PNG";
$ppu->formName = "UploadQueue";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "over";
$ppu->nameToLower = false;
$ppu->requireUpload = true;
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.12"
$ppu->doUpload();
?>
// INSERT INTO DATABASE (it works !)
<?php
if (!function_exists("GetSQLValueString") {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string" ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "" ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "" ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "" ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "" ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "" ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
if (isset($editFormAction)) {
if (isset($_SERVER['QUERY_STRING'])) {
if (!eregi("GP_upload=true", $_SERVER['QUERY_STRING'])) {
$editFormAction .= "&GP_upload=true";
}
} else {
$editFormAction .= "?GP_upload=true";
}
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "UploadQueue") {
$insertSQL = sprintf("INSERT INTO photo (pho_albid, pho_nom, pho_thumb, pho_description, pho_actif, pho_titre) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['pho_albid'], "int",
GetSQLValueString($_POST['Filename'], "text",
GetSQLValueString($thumb .$_POST['Filename'], "text",
GetSQLValueString($_POST['pho_description'], "text",
GetSQLValueString($_POST['pho_actif'], "int",
GetSQLValueString($_POST['pho_titre'], "text");
mysql_select_db($database_marscoiff, $marscoiff);
$Result1 = mysql_query($insertSQL, $marscoiff) or die(mysql_error());
}
?>
// RESIZING FOR THUMB !!! DOESN'T WORK !!!
<?php
// Smart Image Processor PHP 2.0.9
if (isset($_GET['GP_upload'])) {
$sipp2 = new cGraphicMediator("upload", $ppu, "Filename"
$sipp2->setComponent("Auto"
$sipp2->setMatteColor("#FFFFFF"
$sipp2->resizeEx(100, 100, true, false);
$sipp2->cropPos("Center-Center", 100, 100);
$sipp2->overwrite = false;
$sipp2->setMask("##path##thumb_##name##.jpg"
$sipp2->save();
$sipp2->process();
}
?>
<?php
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
?>
// MY FORM (it works !)
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="UploadQueue" id="UploadQueue" onSubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,'','','','','','','');return document.MM_returnValue">
<input name="Filename" type="file" style="display:none" onChange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,'','','','','','','')" />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,63,0" width="550" height="350" id="upload1" align="middle">
<param name="FlashVars" value="url=<?php echo urlencode($GP_uploadAction); ?>&formName=UploadQueue&FlashUpload=true<?php if ($ppu->redirectURL <> '') {echo "&redirectUrl=".$ppu->redirectURL;}?>" />
<param name="movie" value="dmxMultiUploader.swf" />
<param name="quality" value="best" />
<param name="wmode" value="transparent" />
<!--[if !IE]>-->
<embed src="dmxMultiUploader.swf" name="upload1" quality="best" flashvars="url=<?php echo urlencode($GP_uploadAction); ?>&formName=UploadQueue&FlashUpload=true<?php if ($ppu->redirectURL <> '') {echo "&redirectUrl=".$ppu->redirectURL;}?>" wmode="transparent" type="application/x-shockwave-flash" width="550" height="350" pluginspage="www.macromedia.com/go/getflashplayer" />
<!--<![endif]-->
</object>
<input type="hidden" name="Filedata" />
<script type="text/javascript">window.upload1 = document.forms["UploadQueue"].upload1;</script>
<input name="pho_actif" type="hidden" id="pho_actif" value="1">
<input name="pho_titre" type="hidden" id="pho_titre" value="Entrez un titre">
<input name="pho_description" type="hidden" id="pho_description" value="Entrez une description">
<input name="pho_albid" type="hidden" id="pho_albid" value ="<?php echo $row_Dernier_album['alb_id']; ?>">
<input type="hidden" name="MM_insert" value="UploadQueue">
</form>
Replies
Replied 03 Jan 2012 10:15:19
03 Jan 2012 10:15:19 Teodor Kuduschiev replied:
Hello Loïc,
Your SIP code:
Should be moved before:
Your SIP code:
// RESIZING FOR THUMB !!! DOESN'T WORK !!! <?php // Smart Image Processor PHP 2.0.9 if (isset($_GET['GP_upload'])) { $sipp2 = new cGraphicMediator("upload", $ppu, "Filename"; $sipp2->setComponent("Auto"; $sipp2->setMatteColor("#FFFFFF"; $sipp2->resizeEx(100, 100, true, false); $sipp2->cropPos("Center-Center", 100, 100); $sipp2->overwrite = false; $sipp2->setMask("##path##thumb_##name##.jpg"; $sipp2->save(); $sipp2->process(); } ?>
Should be moved before:
if (isset($editFormAction)) { if (isset($_SERVER['QUERY_STRING'])) { if (!eregi("GP_upload=true", $_SERVER['QUERY_STRING'])) { $editFormAction .= "&GP_upload=true"; } } else { $editFormAction .= "?GP_upload=true"; } } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "UploadQueue") { $insertSQL = sprintf("INSERT INTO photo (pho_albid, pho_nom, pho_thumb, pho_description, pho_actif, pho_titre) VALUES (%s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['pho_albid'], "int", GetSQLValueString($_POST['Filename'], "text", GetSQLValueString($thumb .$_POST['Filename'], "text", GetSQLValueString($_POST['pho_description'], "text", GetSQLValueString($_POST['pho_actif'], "int", GetSQLValueString($_POST['pho_titre'], "text"); mysql_select_db($database_marscoiff, $marscoiff); $Result1 = mysql_query($insertSQL, $marscoiff) or die(mysql_error()); } ?>