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
00030 global $sourceFolder;
00031 global $uploadFolder;
00032 $uploadDir = $sourceFolder . "/" . $uploadFolder;
00033
00034 $defaultUploadableFileTypes = '/\.(css|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';
00035 if($uploadableFileTypesArray === false)
00036 $uploadFileTypesRegexp = $defaultUploadableFileTypes;
00037 else {
00038 if(gettype($uploadableFileTypesArray)!="array" || count($uploadableFileTypesArray)==0) {
00039 displayerror("Error in the uploadable types given.");
00040 return false;
00041 }
00042 $uploadFileTypesRegexp = '/\.('.join($uploadableFileTypesArray,"|").')$/i';
00043 }
00044
00046 if (!file_exists($uploadDir)) {
00047 displaywarning("The folder $uploadDir does not exist. Trying to creating it.");
00048 mkdir($uploadDir, 0755);
00049 if (!file_exists($uploadDir)) {
00050 displayerror("Creation of directory failed");
00051 return false;
00052 }
00053 else
00054 displayinfo("Created $uploadDir.");
00055 }
00056 if (!file_exists($uploadDir . '/' . $moduleName)) {
00057 displaywarning("The folder ".$uploadDir.'/'.$moduleName." does not exist. Trying to create it");
00058 mkdir($uploadDir . '/' . $moduleName, 0755);
00059 if (!file_exists($uploadDir. '/' . $moduleName)) {
00060 displayerror("Creation of directory failed");
00061 return false;
00062 }
00063 else
00064 displayinfo("Created ".$uploadDir. '/' . $moduleName);
00065 }
00066
00067 $uploadedFiles = array();
00068
00069 if (isset ($_FILES[$uploadFormName])) {
00070 if(is_array($_FILES[$uploadFormName]['error'])) {
00071 foreach ($_FILES[$uploadFormName]['error'] as $key => $error) {
00072 if ($error == UPLOAD_ERR_OK) {
00073 $tmp_name = $_FILES[$uploadFormName]['tmp_name'][$key];
00074 $upload_filename = $_FILES[$uploadFormName]['name'][$key];
00075 $upload_filetype = $_FILES[$uploadFormName]['type'][$key];
00076
00077 if(preg_match($uploadFileTypesRegexp , $upload_filename , $matches) == 0) {
00078 displayerror("Error while uploading file $upload_filename. Upload of files of this type not allowed.");
00079 continue;
00080 }
00081 if($_FILES[$uploadFormName]['size'][$key]>$maxFileSizeInBytes) {
00082 displayerror("Error while uploading file $upload_filename. Max file size of $maxFileSizeInBytes bytes exceeded.");
00083 continue;
00084 }
00085
00086 $uploadedFilename = saveUploadedFile(
00087 $moduleComponentId, $moduleName, $userId, $upload_filename, $tmp_name,
00088 $upload_filetype, $uploadDir
00089 );
00090
00091 if($uploadedFilename) {
00092 $uploadedFiles[] = $uploadedFilename;
00093 }
00094 }
00095 else {
00096 if($error == UPLOAD_ERR_NO_FILE) continue;
00097 displayerror("Unable to upload file. ".getFileUploadError($error));
00098 }
00099 }
00100 }
00101 else {
00102 $uploadTrue = true;
00103 $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 }
00108 if($uploadTrue && $_FILES[$uploadFormName]['size']>$maxFileSizeInBytes) {
00109 displayerror("Error while uploading file $upload_filename. Max file size of $maxFileSizeInBytes bytes exceeded.");
00110 $uploadTrue = false;
00111 }
00112 if($uploadTrue) {
00113 $uploadedFilename = saveUploadedFile(
00114 $moduleComponentId,$moduleName, $userId, $_FILES[$uploadFormName]['name'],
00115 $_FILES[$uploadFormName]['tmp_name'], $_FILES[$uploadFormName]['type'], $uploadDir
00116 );
00117 }
00118 if($uploadedFilename) {
00119 $uploadedFiles[] = $uploadedFilename;
00120 }
00121 }
00122 }
00123 else {
00124 echo "Sorry, there was a problem uploading your file. UPLOAD L:63 $uploadFormName";
00125 }
00126
00127 return $uploadedFiles;
00128 }
00129
00130 function saveUploadedFile($moduleComponentId,$moduleName, $userId, $uploadFileName, $tempFileName, $uploadFileType, $uploadDir) {
00131 $query = 'SELECT MAX(`upload_fileid`) FROM `' . MYSQL_DATABASE_PREFIX . 'uploads`';
00132 $result = mysql_query($query) or die(mysql_error() . 'upload.lib L:43');
00133 $row = mysql_fetch_row($result);
00134 $upload_fileid = 1;
00135 if(!is_null($row[0])) {
00136 $upload_fileid = $row[0] + 1;
00137 }
00138 $finalName = str_pad($upload_fileid, 10, '0', STR_PAD_LEFT) . '_' . $uploadFileName;
00139 if(strpbrk($uploadFileName, '%#&')) {
00140 displayerror("(\") , ( % ) and ( & ) are not allowed in the file name.");
00141 return false;
00142 }
00143 $duplicateCheckQuery = "SELECT * FROM `" . MYSQL_DATABASE_PREFIX . "uploads` " .
00144 "WHERE `page_modulecomponentid` = $moduleComponentId AND `page_module` = '$moduleName'" .
00145 " AND upload_filename = '$uploadFileName'";
00146 $duplicateCheckResult = mysql_query($duplicateCheckQuery);
00147 if(mysql_num_rows($duplicateCheckResult) >= 1) {
00148 displayerror("A file with the name $uploadFileName already exists. Please use a different filename.");
00149 return false;
00150 }
00151 $query = 'INSERT INTO `' . MYSQL_DATABASE_PREFIX . 'uploads` ' .
00152 '(`page_modulecomponentid`, `page_module`, `upload_fileid`, `upload_filename`, `upload_filetype`, `user_id`) ' .
00153 "VALUES ($moduleComponentId, '$moduleName', $upload_fileid, " .
00154 "'" . mysql_escape_string($uploadFileName) . "', '$uploadFileType', $userId)";
00155 mysql_query($query) or die(mysql_error() . "upload.lib L:148<br />");
00156 if($moduleName=="gallery")
00157 {
00158 $thumb_upload_fileid = $upload_fileid + 1;
00159 $thumb_name="thumb_".$uploadFileName;
00160 $thumb_finalName = str_pad($thumb_upload_fileid, 10, '0', STR_PAD_LEFT) . '_' . $thumb_name;
00161 $thmb = createThumbs($tempFileName,"$uploadDir/$moduleName/$thumb_finalName",136);
00162 if(!$thmb)
00163 {
00164 displayerror("Unable to generate thumbnail / open file. Try later");
00165 return false;
00166 }
00167 $query = 'INSERT INTO `' . MYSQL_DATABASE_PREFIX . 'uploads` ' .
00168 '(`page_modulecomponentid`, `page_module`, `upload_fileid`, `upload_filename`, `upload_filetype`, `user_id`) ' .
00169 "VALUES ($moduleComponentId, '$moduleName', $thumb_upload_fileid, " .
00170 "'" . mysql_escape_string($thumb_name) . "', '$uploadFileType', $userId)";
00171 mysql_query($query) or die(mysql_error() . "upload.lib L:163<br />");
00172 }
00173 move_uploaded_file($tempFileName, "$uploadDir/$moduleName/$finalName");
00174 return $uploadFileName;
00175 }
00176
00177
00182 function getUploadedFiles($moduleComponentId, $moduleName) {
00183 $query = "SELECT `upload_filename`, `upload_filetype`, `upload_time`, `user_id` FROM `" . MYSQL_DATABASE_PREFIX . "uploads` WHERE `page_modulecomponentid` =" . $moduleComponentId . " AND `page_module` = '" . $moduleName . "'";
00184 $result = mysql_query($query);
00185 $fileArray = array ();
00186 while ($row = mysql_fetch_assoc($result))
00187 $fileArray[] = $row;
00188
00189 return $fileArray;
00190 }
00191
00192
00196 function fileCopy($sourcePage_modulecomponentid,$sourcePage_module,$sourceFile_name,
00197 $destinationPage_modulecomponentid,$destinationPage_module,$destinationFile_name,$user_id) {
00198
00199 global $sourceFolder, $uploadFolder;
00200 $uploadDir = $sourceFolder . "/" . $uploadFolder;
00201
00202 $query = "SELECT * FROM `" . MYSQL_DATABASE_PREFIX . "uploads` WHERE `page_modulecomponentid` =" . $sourcePage_modulecomponentid . " AND `upload_filename` =" . mysql_escape_string($sourceFile_name) . "'";
00203 $result = mysql_query($query);
00204 $array1 = mysql_fetch_assoc($result);
00205 $tmp_name = $uploadDir . "/" . $sourcePage_module . "/" . str_repeat("0", (10 - strlen((string) $array1['upload_fileid']))) . $array1['upload_fileid'] . "_" . $sourceFile_name;
00206 $query1= "SELECT MAX(upload_fileid) as MAX FROM `" . MYSQL_DATABASE_PREFIX . "uploads` ";
00207 $result1 = mysql_query($query) or die(mysql_error() . "upload.lib");
00208 $row1 = mysql_fetch_assoc($result);
00209 $upload_fileid = $row1['MAX'] + 1;
00210 $finalname = str_repeat("0", (10 - strlen((string) $upload_fileid))) . $upload_fileid . "_" . $destinationFile_name;
00211 if(!copy($tmp_name, $uploadDir . "/" . $destinationPage_module . "/" . $finalname))
00212 return false;
00213 $query2 = "INSERT INTO `" . MYSQL_DATABASE_PREFIX . "uploads` (`page_modulecomponentid` ,`page_module` , `upload_fileid` , `upload_filename` ," .
00214 " `upload_filetype` , `user_id`) VALUES ('$destinationPage_modulecomponentid', '$destinationPage_module','$upload_fileid'," .
00215 " '" . mysql_escape_string($destinationFile_name) . "', '{$array1['upload_filetype']}','$user_id')";
00216 $result2 = mysql_query($query2);
00217
00218
00219 }
00220
00221 function fileMove($sourcePage_modulecomponentid,$sourcePage_module,$sourceFile_name,
00222 $destinationPage_modulecomponentid,$destinationPage_module,$destinationFile_name,$user_id) {
00223 global $sourceFolder, $uploadFolder;
00224 $uploadDir = "$sourceFolder/$uploadFolder";
00225
00226 $query = "SELECT * FROM `" . MYSQL_DATABASE_PREFIX . "uploads` WHERE `page_modulecomponentid` = $sourcePage_modulecomponentid AND `upload_filename` ='" . mysql_escape_string($sourceFile_name) . "'";
00227 $result = mysql_query($query);
00228 $array1 = mysql_fetch_assoc($result);
00229 $oldname = "$uploadDir/$sourcePage_module/" . str_repeat('0', (10 - strlen((string) $array1['upload_fileid']))) . $array1['upload_fileid'] . "_$sourceFile_name";
00230 $finalname = "$uploadDir/$destinationPage_module/" . str_repeat('0', (10 - strlen((string) $array1['upload_fileid']))) . $array1['upload_fileid'] . "_$destinationFile_name";
00231 rename($oldname,$finalname);
00232 $query2 = "INSERT INTO `" . MYSQL_DATABASE_PREFIX . "uploads` (`page_modulecomponentid`, `page_module`, `upload_fileid`, `upload_filename`, " .
00233 "`upload_filetype`, `user_id`) VALUES ('$destinationPage_modulecomponentid', '$destinationPage_module', '$upload_fileid', " .
00234 " '" . mysql_escape_string($destinationFile_name) . "', '{$array1['upload_filetype']}','$user_id')";
00235 $result2 = mysql_query($query2);
00236 }
00237
00238
00243 function getFileName($moduleComponentId, $page_module, $upload_fileid) {
00244 $query = " SELECT * FROM `" . MYSQL_DATABASE_PREFIX . "uploads` WHERE `page_modulecomponentid` =$moduleComponentId AND `page_module` =$page_module AND `upload_fileid` =$upload_fileid";
00245 $result = mysql_query($query);
00246 if (mysql_num_rows($result) > 0) {
00247 $name = mysql_fetch_assoc($result);
00248 return $name['upload_filename'];
00249 } else
00250 return false;
00251 }
00252
00256 function deleteFile( $moduleComponentId, $page_module, $upload_filename) {
00257 global $uploadFolder;
00258 global $sourceFolder;
00259 $upload_filename = stripslashes($upload_filename);
00260 $query = "SELECT * FROM `" . MYSQL_DATABASE_PREFIX . "uploads`WHERE `page_modulecomponentid` =$moduleComponentId AND `page_module` = '$page_module' AND `upload_filename`= '" . mysql_escape_string($upload_filename) . "'";
00261
00262 $result = mysql_query($query) or die(mysql_error() . "upload L:260");
00263 if(mysql_num_rows($result)<1) return false;
00264 $row = mysql_fetch_assoc($result);
00265 $upload_fileid = $row['upload_fileid'];
00266
00267 $filename = str_repeat("0", (10 - strlen((string) $upload_fileid))) . $upload_fileid . "_" . $upload_filename;
00268 if (@ unlink($sourceFolder . "/" . $uploadFolder . "/" . $page_module . "/" . $filename)) {
00269 } else
00270 displayerror("File data has NOT been deleted from the SERVER");
00271 $query = "DELETE FROM `" . MYSQL_DATABASE_PREFIX . "uploads` WHERE `upload_fileid`=$upload_fileid";
00272 if($page_module=="gallery")
00273 {
00274 $thumb_name = "thumb_".$upload_filename;
00275 deleteFile($moduleComponentId,$page_module,$thumb_name);
00276 }
00277 mysql_query($query);
00278 if (mysql_affected_rows() > 0) {
00279
00280 return true;
00281 } else {
00282 displayerror("File data has NOT been deleted from the database");
00283 return false;
00284 }
00285
00286 }
00287
00288 function getUploadedFilePreviewDeleteForm($moduleComponentId, $moduleName, $deleteFormAction = './+edit') {
00289 global $uploadedFormNumber;
00290 if(!isset($uploadedFormNumber)) $uploadedFormNumber=1;
00291 $uploadedFormNumber += 1;
00292
00293 if(isset($_POST['file_deleted']) && ($_POST['file_deleted'] == "form_$uploadedFormNumber")) {
00294 if(isset($_GET['deletefile'])) {
00295 if(deleteFile($moduleComponentId,$moduleName,escape($_GET['deletefile'])))
00296 displayinfo("The file ".escape($_GET['deletefile'])." has been removed");
00297 else
00298 displayinfo("Unable to remove the file.");
00299 }
00300 }
00301
00302 $uploadedFiles = getUploadedFiles($moduleComponentId, $moduleName);
00303 $uploadedFilesString = "";
00304 foreach($uploadedFiles as $file) {
00305 $uploadedUserEmail = getUserEmail($file['user_id']);
00306 $uploadedUserName = getUserFullName($file['user_id']);
00307 $fileDelete=addslashes($file['upload_filename']);
00308
00309 $uploadedFilesString .= <<<UPLOADEDFILESSTRING
00310 <tr>
00311 <td><a href="./{$file['upload_filename']}" onMouseOver="javascript:showPath('$fileDelete')" target="previewIframe_$uploadedFormNumber">{$file['upload_filename']}</a></td>
00312 <td>$uploadedUserName</td>
00313 <td>$uploadedUserEmail</td>
00314 <td>{$file['upload_time']}</td>
00315 <td><input type='submit' value='Delete' onclick="return checkDeleteUpload(this, '$fileDelete');"></td>
00316 </tr>
00317 UPLOADEDFILESSTRING;
00318 }
00319 global $urlRequestRoot;
00320 global $cmsFolder;
00321 global $STARTSCRIPTS;
00322 if(count($uploadedFiles)>0) {
00323
00324 $smarttablestuff = smarttable::render(array('filestable'),null);
00325 $STARTSCRIPTS .= "initSmartTable();";
00326 $uploadedFilesString =<<<UPLOADEDFILESSTRING
00327 <form action="$deleteFormAction" method="POST" name="deleteFile">
00328 <script language="javascript">
00329 function showPath(fileName) {
00330 path = document.location.pathname;
00331 path = path.split('+');
00332 path = path[0].split('&');
00333 document.getElementById("preview_uploadedfile_$uploadedFormNumber").setAttribute('value',path[0]+fileName);
00334 }
00335 function checkDeleteUpload(butt,fileDel) {
00336 if(confirm('Are you sure you want to delete '+fileDel+'?')) {
00337 butt.form.action+='&deletefile='+fileDel;
00338 butt.form.submit();
00339 }
00340 else
00341 return false;
00342 }
00343
00344 </script>
00345 $smarttablestuff
00346 <table border="1" width="100%">
00347 <tr>
00348
00349
00350 <td height="100" width="100%" style="overflow:scroll">
00351 <center>Preview (only for images)</center>
00352 <iframe name="previewIframe_$uploadedFormNumber" width="100%" style="min-height:200px" ></iframe>
00353 </td>
00354
00355 </tr>
00356 <tr>
00357 <td>
00358 <b>Click</b> for preview
00359 </td>
00360
00361 </tr>
00362 <tr>
00363 <td>
00364 <table class="display" id="filestable" border="1" width="100%">
00365 <thead>
00366 <tr>
00367 <th>File</th>
00368 <th>Uploaded By</th>
00369 <th>Email Id</th>
00370 <th>Upload Time</th>
00371 <th>Delete</th>
00372 </tr>
00373 </thead>
00374 <tbody>
00375 $uploadedFilesString
00376 </tbody>
00377 </table>
00378
00379 </td>
00380
00381
00382 </tr>
00383 <tr>
00384 <td align="right">Path for file (move mouse over name):
00385
00386 <input type="text" style="width:97%" readonly="readonly" id="preview_uploadedfile_$uploadedFormNumber" value="Copy the path from here" />
00387 </td>
00388 </tr>
00389 </table>
00390 <input type="hidden" name="file_deleted" value="form_$uploadedFormNumber">
00391 </form>
00392 UPLOADEDFILESSTRING;
00393 }
00394 else
00395 $uploadedFilesString = "No files associated with this page.";
00396 return $uploadedFilesString;
00397 }
00398
00402 function submitFileUploadForm($moduleComponentId, $moduleName, $userId, $maxFileSizeInBytes = false, $uploadableFileTypesArray = false, $uploadFieldName = 'fileUploadField') {
00403 if($maxFileSizeInBytes===false) $maxFileSizeInBytes = 2*1024*1024;
00404 if(isset($_FILES[$uploadFieldName]['error'][0])) {
00405 $errorCode = $_FILES[$uploadFieldName]['error'][0];
00406 if($errorCode == UPLOAD_ERR_NO_FILE) return true;
00407 if($errorCode != 0) {
00408 displayerror("Error in uploading file. ".getFileUploadError($errorCode));
00409 return true;
00410 }
00411 $uploadedFiles = upload($moduleComponentId, $moduleName, $userId, $uploadFieldName, $maxFileSizeInBytes, $uploadableFileTypesArray);
00412 if(is_array($uploadedFiles) && count($uploadedFiles) > 0)
00413 displayinfo ( "Successfully uploaded file(s) ".join($uploadedFiles,"; ").".");
00414 return $uploadedFiles ;
00415 }
00416 else
00417 return true;
00418 }
00419
00420 function getFileUploadForm($moduleComponentId, $moduleName, $uploadFormAction = './+edit', $maxFileSizeInBytes = false, $uploadFieldCount = 5, $uploadFieldName = 'fileUploadField' ) {
00421 $uploadFormString = <<<UPLOAD
00422 <form action="$uploadFormAction" method="post" enctype="multipart/form-data">
00423 <style type="text/css">
00424 .upload { display : none; }
00425 .show { display : block; }
00426 </style>
00427 <script language="javascript" type="text/javascript">
00428 function toggleuploadfiles(gett) {
00429 if(gett.nextSibling.nextSibling.className != "show")
00430 {
00431 gett.nextSibling.nextSibling.className = "show";
00432 gett = gett.nextSibling.nextSibling;
00433 }
00434 else
00435 {
00436 gett.nextSibling.nextSibling.className = "upload";
00437 gett = gett.nextSibling.nextSibling;
00438 }
00439 }
00440 </script>
00441 UPLOAD;
00442 $uploadFormString .= getFileUploadField($uploadFieldName,$moduleName,$maxFileSizeInBytes);
00443 if($uploadFieldCount >= 2) {
00444 $uploadFormString .= '<input type="button" value="Upload more files" onclick="javascript:toggleuploadfiles(this);" />
00445 <span class="upload">';
00446 for($i=2;$i<=$uploadFieldCount;$i++) {
00447 $uploadFormString .= "<input name=\"".$uploadFieldName."[]\" type=\"file\" />";
00448 if($i!=$uploadFieldCount) $uploadFormString .= '<br />';
00449 }
00450 $uploadFormString .= '</span>';
00451 }
00452 $uploadFormString .= '<input value="Upload" type="submit" />
00453 </form>';
00454 return $uploadFormString;
00455 }
00456
00462 function getFileUploadField($uploadFieldName,$moduleName, $maxFileSizeInBytes = false, $validCheck = "") {
00463 if($maxFileSizeInBytes===false) $maxFileSizeInBytes = 2*1024*1024;
00464 $uploadFormString ='<input type="hidden" name="MAX_FILE_SIZE" value="'.$maxFileSizeInBytes.'" />' .
00465 '<input name="'.$uploadFieldName.'[]" type="file" '.$validCheck.' />
00466 <input type="hidden" name="FileUploadForm" value="'.$uploadFieldName.'" />';
00467 return $uploadFormString;
00468
00469 }
00470
00477 function getMultipleFileUploadField($uploadFieldName, $moduleName, $maxFileSizeInBytes = false, $validCheck = "") {
00478 if($maxFileSizeInBytes===false) $maxFileSizeInBytes = 2*1024*1024;
00479 $uploadFormString ='<input type="hidden" name="MAX_FILE_SIZE" value="'.$maxFileSizeInBytes.'" />' .
00480 '<input name="'.$uploadFieldName.'[]" type="file" multiple '.$validCheck.' />
00481 <input type="hidden" name="FileUploadForm" value="'.$uploadFieldName.'" />';
00482 return $uploadFormString;
00483 }
00484
00485 function getFileUploadError($i) {
00486 $errorcodes = array(UPLOAD_ERR_OK => "There is no error, the file uploaded with success.",
00487 UPLOAD_ERR_INI_SIZE=> "The uploaded file exceeds the upload_max_filesize directive in php.ini.",
00488 UPLOAD_ERR_FORM_SIZE=> "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.",
00489 UPLOAD_ERR_PARTIAL=>"The uploaded file was only partially uploaded.",
00490 UPLOAD_ERR_NO_FILE=> "No file was uploaded.",
00491 UPLOAD_ERR_NO_TMP_DIR=>"Missing a temporary folder.",
00492 UPLOAD_ERR_CANT_WRITE=>"Failed to write file to disk.",
00493 UPLOAD_ERR_EXTENSION=>"File upload stopped by extension.");
00494
00495 return($errorcodes[$i]);
00496 }
00497 function open_image ($file) {
00498
00499 $size=getimagesize($file);
00500 switch($size["mime"]){
00501 case "image/jpeg":
00502 $im = imagecreatefromjpeg($file);
00503 break;
00504 case "image/gif":
00505 $im = imagecreatefromgif($file);
00506 break;
00507 case "image/png":
00508 $im = imagecreatefrompng($file);
00509 break;
00510 default:
00511 $im=false;
00512 break;
00513 }
00514 return $im;
00515 }
00516 function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
00517 {
00518
00519 $img = open_image( "{$pathToImages}" );
00520 if($img!=false){
00521 $width = imagesx( $img );
00522 $height = imagesy( $img );
00523
00524
00525 $new_width = $thumbWidth;
00526
00527 $new_height = $thumbWidth;
00528
00529
00530 $tmp_img = imagecreatetruecolor( $new_width, $new_height );
00531
00532
00533 imagecopyresampled( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
00534
00535
00536 $size=getimagesize("{$pathToImages}");
00537 switch($size["mime"]){
00538 case "image/jpeg":
00539 $im = imagejpeg( $tmp_img, "{$pathToThumbs}" );
00540 break;
00541 case "image/gif":
00542 $im = imagegif( $tmp_img, "{$pathToThumbs}" );
00543 break;
00544 case "image/png":
00545 $im = imagepng( $tmp_img, "{$pathToThumbs}" );
00546 break;
00547 }
00548 return true;
00549 }
00550 return false;
00551 }
00552 ?>