Thormar

upl

Jun 7th, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.91 KB | None | 0 0
  1. $targetFolder = '/uploads'; // Relative to the root
  2.  
  3. if (!empty($_FILES)) {    
  4.    
  5.     $tempFile = $_FILES['Filedata']['tmp_name'];
  6.     $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;    
  7.     $targetFileHd = rtrim($targetPath,'/') . '/hd/' . $_FILES['Filedata']['name'];
  8.     $targetFileBase = rtrim($targetPath,'/') . '/base/' . $_FILES['Filedata']['name'];
  9.     $targetFileMin = rtrim($targetPath,'/') . '/min/' . $_FILES['Filedata']['name'];
  10.     $targetFileThumb = rtrim($targetPath,'/') . '/thumb/' . $_FILES['Filedata']['name'];
  11.     $targetFileLarge = rtrim($targetPath,'/') . '/large/' . $_FILES['Filedata']['name'];
  12.    
  13.     $pathHd=$targetFolder.'/hd/'.$_FILES['Filedata']['name'];
  14.     $pathBase=$targetFolder.'/base/'.$_FILES['Filedata']['name'];
  15.     $pathMin=$targetFolder.'/min/'.$_FILES['Filedata']['name'];
  16.     $pathThumb=$targetFolder.'/thumb/'.$_FILES['Filedata']['name'];
  17.     $pathLarge=$targetFolder.'/large/'.$_FILES['Filedata']['name'];
  18.  
  19.        copy($tempFile,$targetFileHd);
  20.         copy($tempFile,$targetFileBase);
  21.         copy($tempFile,$targetFileMin);
  22.         copy($tempFile,$targetFileThumb);
  23.         copy($tempFile,$targetFileLarge);
  24.        
  25.         $resizeLarge=new resize($targetFileLarge);      
  26.         $resizeHd=new resize($targetFileHd);
  27.         $resizeBase=new resize($targetFileBase);
  28.         $resizeMin=new resize($targetFileMin);
  29.         $resizeThumb=new resize($targetFileThumb);
  30.        
  31.        
  32.         $resizeLarge->resizeImage(360,270, 'exact');        
  33.         $resizeLarge->saveImage($targetFileLarge,90);
  34.        
  35.         $resizeHd->resizeImage(1024, 768, 'exact');        
  36.         $resizeHd->saveImage($targetFileHd, 80);
  37.        
  38.         $resizeBase->resizeImage(1024, 192, 'crop');
  39.         $resizeBase->saveImage($targetFileBase, 80);
  40.        
  41.         $resizeMin->resizeImage(150, 100, 'exact');
  42.         $resizeMin->saveImage($targetFileMin, 80);
  43.        
  44.         $resizeThumb->resizeImage(80, 80, 'exact');
  45.         $resizeThumb->saveImage($targetFileThumb, 80);
  46.        
  47.         $select="SELECT `id`,`name` FROM `media` WHERE `name`='{$_FILES['Filedata']['name']}'";
  48.         $res=  mysql_query($select);
  49.         if(mysql_num_rows($res)>0){
  50.             while($row=mysql_fetch_assoc($res)){
  51.                 $sql="UPDATE `media` set date_added=NOW(),path_hd='{$pathHd}',path_base='{$pathBase}',path_min='{$pathMin}',";
  52.                 $sql.="path_thumb='{$pathThumb}',name='{$_FILES['Filedata']['name']}',path_large='{$pathLarge}' WHERE id={$row['id']}";
  53.                 mysql_query($sql);            
  54.              
  55.             }
  56.         }else{
  57.             $sql="INSERT IGNORE INTO `media` (date_added,path_hd,path_base,path_min,path_thumb,name,path_large) ";
  58.             $sql.="VALUES (NOW(),'{$pathHd}','{$pathBase}','{$pathMin}','{$pathThumb}','{$_FILES['Filedata']['name']}','{$pathLarge}')";
  59.             mysql_query($sql);          
  60.          
  61.         }
Advertisement
Add Comment
Please, Sign In to add comment