Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: PHP  |  size: 3.00 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. try {
  3. $filename = $_FILES['Filedata']['name'];       
  4. $filetmpname = $_FILES['Filedata']['tmp_name'];
  5. $fileType = $_FILES["Filedata"]["type"];
  6. $fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 / 1000);
  7.  
  8. $userid = $_GET['id'];
  9. $car = $_GET['car'];
  10. $profileUploaded = false;
  11.                        
  12. if($car>0)
  13. {
  14.         if(!is_dir('images/'.$userid.'/car'))
  15.         {
  16.         mkdir('images/'.$userid.'/car', 0777, true);
  17. //      chmod('images', 0777);
  18. //      chmod('images/'.$userid, 0777);
  19.         chmod('images/'.$userid.'/car', 0777);
  20.         $profileUploaded = move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$userid."/car/carOriginal".$car.".jpg");
  21.         }
  22.         else
  23.         {
  24.         // Place file on server, into the images folder
  25.         $profileUploaded = move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$userid."/car/carOriginal".$car.".jpg");
  26.         }
  27.        
  28. if($profileUploaded){
  29.  
  30. $filename = "images/".$userid."/car/carOriginal".$car.".jpg";
  31.         // Create image instances
  32.         $src = imagecreatefromjpeg($filename);
  33.         $dest = imagecreatetruecolor(250, 250);
  34.        
  35.         list($width, $height, $type, $attr) = getimagesize($filename);
  36.  
  37.        
  38.         if($width > $height){
  39.        
  40.                 imagecopyresized($dest, $src, 0, 0, 0,  0, 250 , 250 , $width-intval(($width-$height)) , $height);
  41.  
  42.         }
  43.         else if($height >= $width){
  44.  
  45.                 imagecopyresized($dest, $src, 0, 0, 0, 0, 250 , 250 , $width, $height - intval(($height-$width)));
  46.         }
  47.        
  48.        
  49.        
  50.         // Output and free from memory
  51.        
  52.         header('Content-Type: image/jpeg');
  53.         imagejpeg($dest, "images/".$userid."/car/car".$car.".jpg");
  54.        
  55.         imagedestroy($dest);
  56.         imagedestroy($src);
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63. }
  64. else
  65. {
  66.         if(!is_dir('images/'.$userid))
  67.         {
  68.                 mkdir('images/'.$userid, 0777, true);
  69.         //      chmod('images', 0777);
  70.                 chmod('images/'.$userid, 0777);
  71.                 $profileUploaded = move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$userid."/profileOriginal.jpg");
  72.         //      chmod("images/".$userid."/profileOriginal.jpg", 0777);
  73.         }
  74.         else
  75.         {
  76.                 // Place file on server, into the images folder
  77.                 $profileUploaded = move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$userid."/profileOriginal.jpg");
  78.         }
  79.  
  80.  
  81.  
  82.  
  83.  
  84. if($profileUploaded){
  85.  
  86. $filename = 'images/'.$userid.'/profileOriginal.jpg';
  87.        
  88.         // Create image instances
  89.         $src = imagecreatefromjpeg($filename);
  90.         $dest = imagecreatetruecolor(250, 250);
  91.        
  92.         list($width, $height, $type, $attr) = getimagesize($filename);
  93.  
  94.        
  95.         if($width > $height){
  96.        
  97.                 imagecopyresized($dest, $src, 0, 0, 0,  0, 250 , 250 , $width-intval(($width-$height)) , $height);
  98.  
  99.         }
  100.         else if($height >= $width){
  101.  
  102.                 imagecopyresized($dest, $src, 0, 0, 0, 0, 250 , 250 , $width, $height - intval(($height-$width)));
  103.         }
  104.        
  105.        
  106.        
  107.         // Output and free from memory
  108.        
  109.         header('Content-Type: image/jpeg');
  110.         imagejpeg($dest, 'images/'.$userid.'/profile.jpg');
  111.        
  112.         imagedestroy($dest);
  113.         imagedestroy($src);
  114. }
  115.        
  116. }
  117.  
  118.  
  119.  
  120. }
  121. catch (Exception $e)
  122. {
  123.        
  124.     $err = 'Exception caught: '.  $e->getMessage(). "\n";
  125.     //$myFile = "testfile.txt";
  126.                 //$fh = fopen($myFile, 'w') or die("can't open file");
  127.                                        
  128.                 //fwrite($fh, $err);
  129.                 //fclose($fh);
  130. }
  131.  
  132. ?>