00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 {
00004 header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005 echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006 echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007 exit(1);
00008 }
00027 function upload($moduleComponentId, $moduleName, $userId, $uploadFormName, $maxFileSizeInBytes=false, $uploadableFileTypesArray = false) {
00028 if($maxFileSizeInBytes===false) $maxFileSizeInBytes = 2*1024*1024;
00029 global $sourceFolder;
00030 global $uploadFolder;
00031 $uploadDir = $sourceFolder . "/" . $uploadFolder;
00032
00033 $defaultUploadableFileTypes = '/\.(css|xlsx|gif|png|jpe?g|js|html|xml|pdf|doc|docx|ods|odt|oft|pps|ppt|pptx|avi|txt|std|stc|sti|stw|svgz?|sxc|sx.|tex|tiff|txt|chm|mp3|mp2|wave?|ogg|mpe?g|wmv|wma|wmf|rm|avi|gzip|gz|rar|bmp|psd|bz2|tar|zip|swf|fla|flv|eps|ico|xcf|m3u|lit|bcf|xls|mov|xlr|exe|7?z)$/i';
00034 if($uploadableFileTypesArray === false)
00035 $uploadFileTypesRegexp = $defaultUploadableFileTypes;
00036 else {
00037 if(gettype($uploadableFileTypesArray)!="array" || count($uploadableFileTypesArray)==0) {
00038 displayerror("Error in the uploadable types given.");
00039 return false;
00040 }
00041 $uploadFileTypesRegexp = '/\.('.join($uploadableFileTypesArray,"|").')$/i';
00042 }
00044 if (!file_exists($uploadDir)) {
00045 displaywarning("The folder $uploadDir does not exist. Trying to creating it.");
00046 mkdir($uploadDir, 0755);
00047 if (!file_exists($uploadDir)) {
00048 displayerror("Creation of directory failed");
00049 return false;
00050 }
00051 else
00052 displayinfo("Created $uploadDir.");
00053 }
00055 if (!file_exists($uploadDir . '/' . $moduleName)) {
00056 displaywarning("The folder ".$uploadDir.'/'.$moduleName." does not exist. Trying to create it");
00057 mkdir($uploadDir . '/' . $moduleName, 0755);
00058 if (!file_exists($uploadDir. '/' . $moduleName)) {
00059 displayerror("Creation of directory failed");
00060 return false;
00061 }
00062 else
00063 displayinfo("Created ".$uploadDir. '/' . $moduleName);
00064 }
00065
00066 $uploadedFiles = array();
00067
00068 if (isset ($_FILES[$uploadFormName])) {
00069 if(is_array($_FILES[$uploadFormName]['error'])) {
00070 foreach ($_FILES[$uploadFormName]['error'] as $key => $error) {
00071 if ($error == UPLOAD_ERR_OK) {
00072 $tmp_name = $_FILES[$uploadFormName]['tmp_name'][$key];
00073 $upload_filename = $_FILES[$uploadFormName]['name'][$key];
00074 $upload_filetype = $_FILES[$uploadFormName]['type'][$key];
00075
00076 if(preg_match($uploadFileTypesRegexp , $upload_filename , $matches) == 0) {
00077 displayerror("Error while uploading file $upload_filename. Upload of files of this type not allowed.");
00078 continue;
00079 }
00080 if($_FILES[$uploadFormName]['size'][$key]>$maxFileSizeInBytes) {
00081 displayerror("Error while uploading file $upload_filename. Max file size of $maxFileSizeInBytes bytes exceeded.");
00082 continue;
00083 }
00084
00085 $uploadedFilename = saveUploadedFile(
00086 $moduleComponentId, $moduleName, $userId, $upload_filename, $tmp_name,
00087 $upload_filetype, $uploadDir
00088 );
00089
00090 if($uploadedFilename) {
00091 $uploadedFiles[] = $uploadedFilename;
00092 }
00093 }
00094 else {
00095 if($error == UPLOAD_ERR_NO_FILE) continue;
00096 displayerror("Unable to upload file. ".getFileUploadError($error));
00097 }
00098 }
00099 }
00100 else {
00101 $uploadTrue = true;
00102 $upload_filename = $_FILES[$uploadFormName]['name'];
00104 if(preg_match($uploadFileTypesRegexp , $upload_filename , $matches) == 0) {
00105 displayerror("Error while uploading file $upload_filename. Upload of files of this type not allowed.");
00106 $uploadTrue = false;
00107 }
00109 if($uploadTrue && $_FILES[$uploadFormName]['size']>$maxFileSizeInBytes) {
00110 displayerror("Error while uploading file $upload_filename. Max file size of $maxFileSizeInBytes bytes exceeded.");
00111 $uploadTrue = false;
00112 }
00113 if($uploadTrue) {
00114 $uploadedFilename = saveUploadedFile(
00115 $moduleComponentId,$moduleName, $userId, $_FILES[$uploadFormName]['name'],
00116 $_FILES[$uploadFormName]['tmp_name'], $_FILES[$uploadFormName]['type'], $uploadDir
00117 );
00118 }
00119 if($uploadedFilename) {
00120 $uploadedFiles[] = $uploadedFilename;
00121 }
00122 }
00123 }
00124 else {
00125 echo "Sorry, there was a problem uploading your file. UPLOAD L:123 $uploadFormName";
00126 }
00127
00128 return $uploadedFiles;
00129 }
00141 function saveUploadedFile($moduleComponentId,$moduleName, $userId, $uploadFileName, $tempFileName, $uploadFileType, $uploadDir) {
00142 $query = 'SELECT MAX(`upload_fileid`) FROM `' . MYSQL_DATABASE_PREFIX . 'uploads`';
00143 $result = mysql_query($query) or die(mysql_error() . 'upload.lib L:131');
00144 $row = mysql_fetch_row($result);
00145 $upload_fileid = 1;
00146 if(!is_null($row[0])) {
00147 $upload_fileid = $row[0] + 1;
00148 }
00149 $finalName = str_pad($upload_fileid, 10, '0', STR_PAD_LEFT) . '_' . $uploadFileName;
00151 if(strpbrk($uploadFileName, '%#&')) {
00152 displayerror("(\") , ( % ) and ( & ) are not allowed in the file name.");
00153 return false;
00154 }
00155 $duplicateCheckQuery = "SELECT * FROM `" . MYSQL_DATABASE_PREFIX . "uploads` " .
00156 "WHERE `page_modulecomponentid` = $moduleComponentId AND `page_module` = '$moduleName'" .
00157 " AND upload_filename = '$uploadFileName'";
00158 $duplicateCheckResult = mysql_query($duplicateCheckQuery);
00160 if(mysql_num_rows($duplicateCheckResult) >= 1) {
00161 displayerror("A file with the name $uploadFileName already exists. Please use a different filename.");
00162 return false;
00163 }
00164 $query = 'INSERT INTO `' . MYSQL_DATABASE_PREFIX . 'uploads` ' .
00165 '(`page_modulecomponentid`, `page_module`, `upload_fileid`, `upload_filename`, `upload_filetype`, `user_id`) ' .
00166 "VALUES ($moduleComponentId, '$moduleName', $upload_fileid, " .
00167 "'" . mysql_escape_string($uploadFileName) . "', '$uploadFileType', $userId)";
00168 mysql_query($query) or die(mysql_error() . "upload.lib L:158<br />");
00170 if($moduleName=="gallery")
00171 {
00172 $thumb_upload_fileid = $upload_fileid + 1;
00173 $thumb_name="thumb_".$uploadFileName;
00174 $thumb_finalName = str_pad($thumb_upload_fileid, 10, '0', STR_PAD_LEFT) . '_' . $thumb_name;
00175 $thmb = createThumbs($tempFileName,"$uploadDir/$moduleName/$thumb_finalName",136);
00176 if(!$thmb)
00177 {
00178 displayerror("Unable to generate thumbnail / open file. Try later");
00179 return false;
00180 }
00181 $query = 'INSERT INTO `' . MYSQL_DATABASE_PREFIX . 'uploads` ' .
00182 '(`page_modulecomponentid`, `page_module`, `upload_fileid`, `upload_filename`, `upload_filetype`, `user_id`) ' .
00183 "VALUES ($moduleComponentId, '$moduleName', $thumb_upload_fileid, " .
00184 "'" . mysql_escape_string($thumb_name) . "', '$uploadFileType', $userId)";
00185 mysql_query($query) or die(mysql_error() . "upload.lib L:163<br />");
00186 }
00187 move_uploaded_file($tempFileName, "$uploadDir/$moduleName/$finalName");
00188 return $uploadFileName;
00189 }
00190
00200 function getUploadedFiles($moduleComponentId, $moduleName) {
00201 $query = "SELECT `upload_filename`, `upload_filetype`, `upload_time`, `user_id` FROM `" . MYSQL_DATABASE_PREFIX . "uploads` WHERE `page_modulecomponentid` =" . $moduleComponentId . " AND `page_module` = '" . $moduleName . "'";
00202 $result = mysql_query($query);
00203 $fileArray = array ();
00204 while ($row = mysql_fetch_assoc($result))
00205 $fileArray[] = $row;
00206
00207 return $fileArray;
00208 }
00209
00224 function fileCopy($sourcePage_modulecomponentid,$sourcePage_module,$sourceFile_name,
00225 $destinationPage_modulecomponentid,$destinationPage_module,$destinationFile_name,$user_id) {
00226
00227 global $sourceFolder, $uploadFolder;
00228 $uploadDir = $sourceFolder . "/" . $uploadFolder;
00229
00230 $query = "SELECT * FROM `" . MYSQL_DATABASE_PREFIX . "uploads` WHERE `page_modulecomponentid` =" . $sourcePage_modulecomponentid . " AND `upload_filename` =" . mysql_escape_string($sourceFile_name) . "'";
00231 $result = mysql_query($query);
00232 $array1 = mysql_fetch_assoc($result);
00233 $tmp_name = $uploadDir . "/" . $sourcePage_module . "/" . str_repeat("0", (10 - strlen((string) $array1['upload_fileid']))) . $array1['upload_fileid'] . "_" . $sourceFile_name;
00234 $query1= "SELECT MAX(upload_fileid) as MAX FROM `" . MYSQL_DATABASE_PREFIX . "uploads` ";
00235 $result1 = mysql_query($query) or die(mysql_error() . "upload.lib");
00236 $row1 = mysql_fetch_assoc($result);
00237 $upload_fileid = $row1['MAX'] + 1;
00238 $finalname = str_repeat("0", (10 - strlen((string) $upload_fileid))) . $upload_fileid . "_" . $destinationFile_name;
00239 if(!copy($tmp_name, $uploadDir . "/" . $destinationPage_module . "/" . $finalname))
00240 return false;
00241 $query2 = "INSERT INTO `" . MYSQL_DATABASE_PREFIX . "uploads` (`page_modulecomponentid` ,`page_module` , `upload_fileid` , `upload_filename` ," .
00242 " `upload_filetype` , `user_id`) VALUES ('$destinationPage_modulecomponentid', '$destinationPage_module','$upload_fileid'," .
00243 " '" . mysql_escape_string($destinationFile_name) . "', '{$array1['upload_filetype']}','$user_id')";
00244 $result2 = mysql_query($query2);
00245
00246
00247 }
00248
00261 function fileMove($sourcePage_modulecomponentid,$sourcePage_module,$sourceFile_name,
00262 $destinationPage_modulecomponentid,$destinationPage_module,$destinationFile_name,$user_id) {
00263 global $sourceFolder, $uploadFolder;
00264 $uploadDir = "$sourceFolder/$uploadFolder";
00265
00266 $query = "SELECT * FROM `" . MYSQL_DATABASE_PREFIX . "uploads` WHERE `page_modulecomponentid` = $sourcePage_modulecomponentid AND `upload_filename` ='" . mysql_escape_string($sourceFile_name) . "'";
00267 $result = mysql_query($query);
00268 $array1 = mysql_fetch_assoc($result);
00269 $oldname = "$uploadDir/$sourcePage_module/" . str_repeat('0', (10 - strlen((string) $array1['upload_fileid']))) . $array1['upload_fileid'] . "_$sourceFile_name";
00270 $finalname = "$uploadDir/$destinationPage_module/" . str_repeat('0', (10 - strlen((string) $array1['upload_fileid']))) . $array1['upload_fileid'] . "_$destinationFile_name";
00271 rename($oldname,$finalname);
00272 $query2 = "INSERT INTO `" . MYSQL_DATABASE_PREFIX . "uploads` (`page_modulecomponentid`, `page_module`, `upload_fileid`, `upload_filename`, " .
00273 "`upload_filetype`, `user_id`) VALUES ('$destinationPage_modulecomponentid', '$destinationPage_module', '$upload_fileid', " .
00274 " '" . mysql_escape_string($destinationFile_name) . "', '{$array1['upload_filetype']}','$user_id')";
00275 $result2 = mysql_query($query2);
00276 }
00277
00278
00288 function getFileName($moduleComponentId, $page_module, $upload_fileid) {
00289 $query = " SELECT * FROM `" . MYSQL_DATABASE_PREFIX . "uploads` WHERE `page_modulecomponentid` =$moduleComponentId AND `page_module` =$page_module AND `upload_fileid` =$upload_fileid";
00290 $result = mysql_query($query);
00291 if (mysql_num_rows($result) > 0) {
00292 $name = mysql_fetch_assoc($result);
00293 return $name['upload_filename'];
00294 } else
00295 return false;
00296 }
00297
00298
00307 function deleteFile( $moduleComponentId, $page_module, $upload_filename) {
00308 global $uploadFolder;
00309 global $sourceFolder;
00310 $upload_filename = stripslashes($upload_filename);
00311 $query = "SELECT * FROM `" . MYSQL_DATABASE_PREFIX . "uploads`WHERE `page_modulecomponentid` =$moduleComponentId AND `page_module` = '$page_module' AND `upload_filename`= '" . mysql_escape_string($upload_filename) . "'";
00312
00313 $result = mysql_query($query) or displayerror(mysql_error() . "upload L:260");
00314 if(mysql_num_rows($result)<1) return false;
00315 $row = mysql_fetch_assoc($result);
00316 $upload_fileid = $row['upload_fileid'];
00317
00318 $filename = str_repeat("0", (10 - strlen((string) $upload_fileid))) . $upload_fileid . "_" . $upload_filename;
00319 if (@ unlink($sourceFolder . "/" . $uploadFolder . "/" . $page_module . "/" . $filename)) {
00320 } else
00321 displayerror("File data has NOT been deleted from the SERVER");
00322 $query = "DELETE FROM `" . MYSQL_DATABASE_PREFIX . "uploads` WHERE `upload_fileid`=$upload_fileid";
00323 if($page_module=="gallery")
00324 {
00325 $thumb_name = "thumb_".$upload_filename;
00326 deleteFile($moduleComponentId,$page_module,$thumb_name);
00327 }
00328 mysql_query($query);
00329 if (mysql_affected_rows() > 0) {
00330
00331 return true;
00332 } else {
00333 displayerror("File data has NOT been deleted from the database");
00334 return false;
00335 }
00336
00337 }
00347 function getUploadedFilePreviewDeleteForm($moduleComponentId, $moduleName, $deleteFormAction = './+edit') {
00348 global $uploadedFormNumber;
00349 if(!isset($uploadedFormNumber)) $uploadedFormNumber=1;
00350 $uploadedFormNumber += 1;
00351
00352 if(isset($_POST['file_deleted']) && ($_POST['file_deleted'] == "form_$uploadedFormNumber")) {
00353 if(isset($_GET['deletefile'])) {
00354 if(deleteFile($moduleComponentId,$moduleName,escape($_GET['deletefile'])))
00355 displayinfo("The file ".escape($_GET['deletefile'])." has been removed");
00356 else
00357 displayinfo("Unable to remove the file.");
00358 }
00359 }
00360
00361 $uploadedFiles = getUploadedFiles($moduleComponentId, $moduleName);
00362 $uploadedFilesString = "";
00363 foreach($uploadedFiles as $file) {
00364 $uploadedUserEmail = getUserEmail($file['user_id']);
00365 $uploadedUserName = getUserFullName($file['user_id']);
00366 $fileDelete=addslashes($file['upload_filename']);
00367
00368 $uploadedFilesString .= <<<UPLOADEDFILESSTRING
00369 <tr>
00370 <td><a href="./{$file['upload_filename']}" onMouseOver="javascript:showPath('$fileDelete')" target="previewIframe_$uploadedFormNumber">{$file['upload_filename']}</a></td>
00371 <td>$uploadedUserName</td>
00372 <td>$uploadedUserEmail</td>
00373 <td>{$file['upload_time']}</td>
00374 <td><input type='submit' value='Delete' onclick="return checkDeleteUpload(this, '$fileDelete');"></td>
00375 </tr>
00376 UPLOADEDFILESSTRING;
00377 }
00378 global $urlRequestRoot;
00379 global $cmsFolder;
00380 global $STARTSCRIPTS;
00381 if(count($uploadedFiles)>0) {
00382
00383 $smarttablestuff = smarttable::render(array('filestable'),null);
00384 $STARTSCRIPTS .= "initSmartTable();";
00385 $uploadedFilesString =<<<UPLOADEDFILESSTRING
00386 <form action="$deleteFormAction" method="POST" name="deleteFile">
00387 <script language="javascript">
00388 function showPath(fileName) {
00389 path = document.location.pathname;
00390 path = path.split('+');
00391 path = path[0].split('&');
00392 document.getElementById("preview_uploadedfile_$uploadedFormNumber").setAttribute('value',path[0]+fileName);
00393 }
00394 function checkDeleteUpload(butt,fileDel) {
00395 if(confirm('Are you sure you want to delete '+fileDel+'?')) {
00396 butt.form.action+='&deletefile='+fileDel;
00397 butt.form.submit();
00398 }
00399 else
00400 return false;
00401 }
00402
00403 </script>
00404 $smarttablestuff
00405 <table border="1" width="100%">
00406 <tr>
00407
00408
00409 <td height="100" width="100%" style="overflow:scroll">
00410 <center>Preview (only for images)</center>
00411 <iframe name="previewIframe_$uploadedFormNumber" width="100%" style="min-height:200px" ></iframe>
00412 </td>
00413
00414 </tr>
00415 <tr>
00416 <td>
00417 <b>Click</b> for preview
00418 </td>
00419
00420 </tr>
00421 <tr>
00422 <td>
00423 <table class="display" id="filestable" border="1" width="100%">
00424 <thead>
00425 <tr>
00426 <th>File</th>
00427 <th>Uploaded By</th>
00428 <th>Email Id</th>
00429 <th>Upload Time</th>
00430 <th>Delete</th>
00431 </tr>
00432 </thead>
00433 <tbody>
00434 $uploadedFilesString
00435 </tbody>
00436 </table>
00437
00438 </td>
00439
00440
00441 </tr>
00442 <tr>
00443 <td align="right">Path for file (move mouse over name):
00444
00445 <input type="text" style="width:97%" readonly="readonly" id="preview_uploadedfile_$uploadedFormNumber" value="Copy the path from here" />
00446 </td>
00447 </tr>
00448 </table>
00449 <input type="hidden" name="file_deleted" value="form_$uploadedFormNumber">
00450 </form>
00451 UPLOADEDFILESSTRING;
00452 }
00453 else
00454 $uploadedFilesString = "No files associated with this page.";
00455 return $uploadedFilesString;
00456 }
00457
00470 function submitFileUploadForm($moduleComponentId, $moduleName, $userId, $maxFileSizeInBytes = false, $uploadableFileTypesArray = false, $uploadFieldName = 'fileUploadField') {
00471 if($maxFileSizeInBytes===false) $maxFileSizeInBytes = 2*1024*1024;
00472 if(isset($_FILES[$uploadFieldName]['error'][0])) {
00473 $errorCode = $_FILES[$uploadFieldName]['error'][0];
00474 if($errorCode == UPLOAD_ERR_NO_FILE) return true;
00475 if($errorCode != 0) {
00476 displayerror("Error in uploading file. ".getFileUploadError($errorCode));
00477 return true;
00478 }
00479 $uploadedFiles = upload($moduleComponentId, $moduleName, $userId, $uploadFieldName, $maxFileSizeInBytes, $uploadableFileTypesArray);
00480 if(is_array($uploadedFiles) && count($uploadedFiles) > 0)
00481 displayinfo ( "Successfully uploaded file(s) ".join($uploadedFiles,"; ").".");
00482 return $uploadedFiles ;
00483 }
00484 else
00485 return true;
00486 }
00487
00500 function getFileUploadForm($moduleComponentId, $moduleName, $uploadFormAction = './+edit', $maxFileSizeInBytes = false, $uploadFieldCount = 5, $uploadFieldName = 'fileUploadField' ) {
00501 $uploadFormString = <<<UPLOAD
00502 <form action="$uploadFormAction" method="post" enctype="multipart/form-data">
00503 <style type="text/css">
00504 .upload { display : none; }
00505 .show { display : block; }
00506 </style>
00507 <script language="javascript" type="text/javascript">
00508 function toggleuploadfiles(gett) {
00509 if(gett.nextSibling.nextSibling.className != "show")
00510 {
00511 gett.nextSibling.nextSibling.className = "show";
00512 gett = gett.nextSibling.nextSibling;
00513 }
00514 else
00515 {
00516 gett.nextSibling.nextSibling.className = "upload";
00517 gett = gett.nextSibling.nextSibling;
00518 }
00519 }
00520 </script>
00521 UPLOAD;
00522 $uploadFormString .= getFileUploadField($uploadFieldName,$moduleName,$maxFileSizeInBytes);
00523 if($uploadFieldCount >= 2) {
00524 $uploadFormString .= '<input type="button" value="Upload more files" onclick="javascript:toggleuploadfiles(this);" />
00525 <span class="upload">';
00526 for($i=2;$i<=$uploadFieldCount;$i++) {
00527 $uploadFormString .= "<input name=\"".$uploadFieldName."[]\" type=\"file\" />";
00528 if($i!=$uploadFieldCount) $uploadFormString .= '<br />';
00529 }
00530 $uploadFormString .= '</span>';
00531 }
00532 $uploadFormString .= '<input value="Upload" type="submit" />
00533 </form>';
00534 return $uploadFormString;
00535 }
00536
00546 function getFileUploadField($uploadFieldName,$moduleName, $maxFileSizeInBytes = false, $validCheck = "") {
00547 if($maxFileSizeInBytes===false) $maxFileSizeInBytes = 2*1024*1024;
00548 $uploadFormString ='<input type="hidden" name="MAX_FILE_SIZE" value="'.$maxFileSizeInBytes.'" />' .
00549 '<input name="'.$uploadFieldName.'[]" type="file" '.$validCheck.' />
00550 <input type="hidden" name="FileUploadForm" value="'.$uploadFieldName.'" />';
00551 return $uploadFormString;
00552
00553 }
00554
00564 function getMultipleFileUploadField($uploadFieldName, $moduleName, $maxFileSizeInBytes = false, $validCheck = "") {
00565 if($maxFileSizeInBytes===false) $maxFileSizeInBytes = 2*1024*1024;
00566 $uploadFormString ='<input type="hidden" name="MAX_FILE_SIZE" value="'.$maxFileSizeInBytes.'" />' .
00567 '<input name="'.$uploadFieldName.'[]" type="file" multiple '.$validCheck.' />
00568 <input type="hidden" name="FileUploadForm" value="'.$uploadFieldName.'" />';
00569 return $uploadFormString;
00570 }
00577 function getFileUploadError($i) {
00578 $errorcodes = array(UPLOAD_ERR_OK => "There is no error, the file uploaded with success.",
00579 UPLOAD_ERR_INI_SIZE=> "The uploaded file exceeds the upload_max_filesize directive in php.ini.",
00580 UPLOAD_ERR_FORM_SIZE=> "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.",
00581 UPLOAD_ERR_PARTIAL=>"The uploaded file was only partially uploaded.",
00582 UPLOAD_ERR_NO_FILE=> "No file was uploaded.",
00583 UPLOAD_ERR_NO_TMP_DIR=>"Missing a temporary folder.",
00584 UPLOAD_ERR_CANT_WRITE=>"Failed to write file to disk.",
00585 UPLOAD_ERR_EXTENSION=>"File upload stopped by extension.");
00586
00587 return($errorcodes[$i]);
00588 }
00589
00596 function open_image ($file) {
00597
00598 $size=getimagesize($file);
00599 switch($size["mime"]){
00600 case "image/jpeg":
00601 $im = imagecreatefromjpeg($file);
00602 break;
00603 case "image/gif":
00604 $im = imagecreatefromgif($file);
00605 break;
00606 case "image/png":
00607 $im = imagecreatefrompng($file);
00608 break;
00609 default:
00610 $im=false;
00611 break;
00612 }
00613 return $im;
00614 }
00623 function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
00624 {
00625
00626 $img = open_image( "{$pathToImages}" );
00627 if($img!=false){
00628 $width = imagesx( $img );
00629 $height = imagesy( $img );
00630
00631
00632 $new_width = $thumbWidth;
00633
00634 $new_height = $thumbWidth;
00635
00636
00637 $tmp_img = imagecreatetruecolor( $new_width, $new_height );
00638
00639
00640 imagecopyresampled( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
00641
00642
00643 $size=getimagesize("{$pathToImages}");
00644 switch($size["mime"]){
00645 case "image/jpeg":
00646 $im = imagejpeg( $tmp_img, "{$pathToThumbs}" );
00647 break;
00648 case "image/gif":
00649 $im = imagegif( $tmp_img, "{$pathToThumbs}" );
00650 break;
00651 case "image/png":
00652 $im = imagepng( $tmp_img, "{$pathToThumbs}" );
00653 break;
00654 }
00655 return true;
00656 }
00657 return false;
00658 }
00659 ?>