By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,341 Members | 1,726 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,341 IT Pros & Developers. It's quick & easy.

how to implement uploadify with my own custom upload.php

anfetienne
100+
P: 424
Hi,

I have just downloaded uploadify and have run a few tests to see if it works straight away on my server which it does.

this is the tutorial i found for implementing but it is not clear at all: uploadify tutorial. i want to be able to use my own script to resize, rename and then move it to it's proper location

this is the upload code that it uses
Expand|Select|Wrap|Line Numbers
  1. if (!empty($_FILES)) {
  2.     $tempFile = $_FILES['Filedata']['tmp_name'];
  3.     $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
  4.     $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
  5.  
  6.     // $fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
  7.     // $fileTypes  = str_replace(';','|',$fileTypes);
  8.     // $typesArray = split('\|',$fileTypes);
  9.     // $fileParts  = pathinfo($_FILES['Filedata']['name']);
  10.  
  11.     // if (in_array($fileParts['extension'],$typesArray)) {
  12.         // Uncomment the following line if you want to make the directory if it doesn't exist
  13.         // mkdir(str_replace('//','/',$targetPath), 0755, true);
  14.  
  15.         move_uploaded_file($tempFile,$targetFile);
  16.         echo "1";
  17.     // } else {
  18.     //     echo 'Invalid file type.';
  19.     // }
  20. }
  21.  
and this is what i want to change it to
Expand|Select|Wrap|Line Numbers
  1. <? session_start();
  2. include ("admin-dbcon.php");
  3.  
  4. $userName = $_SESSION['_amember_user']['login'];
  5. $firstName = $_SESSION['_amember_user']['name_f'];
  6. $firstName = ucfirst($firstName); 
  7. $lastName = $_SESSION['_amember_user']['name_l'];
  8. $lastName = ucfirst($lastName); 
  9. $random_digit = $_POST['ID'];
  10. $returnURL = $_POST['returnURL'];
  11.  
  12. $thumbTemp=mkdir("uploads/tmp/$userName/t/", 0777); 
  13. $mainTemp=mkdir("uploads/tmp/$userName/m/", 0777); 
  14.  
  15. $albumName = $_POST['albumName'];
  16.  
  17.  
  18. include('SimpleImage.php');
  19. while(list($key,$value) = each($_FILES['file']['name']))
  20.         {
  21.             if(!empty($value))
  22.             {
  23.                 $filename = $value;
  24.                     $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
  25.  
  26.                     $add = "uploads/tmp/$userName/m/$filename";
  27.                     $tempFLDR = "uploads/tmp/$userName/t/$filename";
  28.                        //echo $_FILES['images']['type'][$key];
  29.                  // echo "<br>";
  30.                     copy($_FILES['file']['tmp_name'][$key], $add);
  31.                     chmod("$add",0777);
  32.                     copy($_FILES['file']['tmp_name'][$key], $tempFLDR);
  33.                     chmod("$tempFLDR",0777);
  34.  
  35. $folderPath="upload/$random_digit/";
  36.             }
  37.  
  38. $imgSize = getimagesize($add);
  39. echo $details[0].'<br/>';
  40. echo $details[1].'<br/>';
  41.  
  42.             if ($imgSize[0] > $imgSize[1]){
  43.             $image = new SimpleImage();
  44.             $image->load("$add");
  45.             $image->resize(450,350);
  46.             $image->save("$add"); 
  47.  
  48.             $image = new SimpleImage();
  49.             $image->load("$tempFLDR");
  50.             $image->resize(100,100);
  51.             $image->save("$tempFLDR"); 
  52.             } 
  53.             elseif ($imgSize[1] > $imgSize[0]) {
  54.             $image = new SimpleImage();
  55.             $image->load("$add");
  56.             $image->resize(240,350);
  57.             $image->save("$add"); 
  58.  
  59.             $image = new SimpleImage();
  60.             $image->load("$tempFLDR");
  61.             $image->resize(100,100);
  62.             $image->save("$tempFLDR"); 
  63.             }
  64.         }
  65.  
  66. mysql_connect($hostname,$username,$password);
  67. @mysql_select_db($database) or die( "Unable to select database");
  68.  
  69. // Select column 1 from table name where column name = $your_var.
  70.  
  71. // If mysql_query returns false, we'll die with the error.
  72. $result = mysql_query("SELECT * FROM imgUpload WHERE tempID = {$random_digit}");
  73.  
  74. // If a there is a match
  75. if ( mysql_num_rows( $result ) > 0 )
  76. {
  77. $row = mysql_fetch_array( $result );
  78.  
  79. //fill in details about the path
  80. $path="uploads/tmp/$userName/m/";
  81. $pathA="uploads/$userName/$albumName/";
  82. //variable used for the name of each file
  83. $i=$row['lastDigit'];
  84.  
  85. $od = opendir($path);
  86. while (false !== ($filename = readdir($od)))
  87. {
  88.     //you can add any type of filenames you wish to skip (for instance Thumbs.db on windows)
  89.     if($filename != '.' && $filename != '..' && !is_dir($path.$filename))
  90.     {
  91.         //we give files a name - here we use increasing numbers for jpg files:
  92.         if(rename($path.$filename, $pathA.$i++.'.jpg'))
  93.         echo '<br />';
  94.     }
  95. }
  96.  
  97. closedir($od);
  98.  
  99.  
  100. //fill in details about the path
  101. $pathT="uploads/tmp/$userName/t/";
  102. $pathF="uploads/$userName/$albumName/";
  103. //variable used for the name of each file
  104. $i=$row['lastDigit'];
  105.  
  106. $odT = opendir($pathT);
  107. while (false !== ($filename = readdir($odT)))
  108. {
  109.     //you can add any type of filenames you wish to skip (for instance Thumbs.db on windows)
  110.     if($filename != '.' && $filename != '..' && !is_dir($pathT.$filename))
  111.     {
  112.         //we give files a name - here we use increasing numbers for jpg files:
  113.         if(rename($pathT.$filename, $pathF.$i++.'b.jpg'))
  114.         echo '<br />';
  115.     }
  116. }
  117. closedir($odT);
  118.  
  119.  
  120.  
  121. $query="
  122.  
  123. UPDATE imgUpload SET 
  124.  
  125.             lastDigit='{$i}' 
  126.  
  127.             WHERE tempID= '{$random_digit}' ";
  128.  
  129. }
  130.  
  131. else
  132. {
  133. //fill in details about the path
  134. $path="uploads/tmp/$userName/m/";
  135. $pathA="uploads/$userName/$albumName/";
  136. //variable used for the name of each file
  137. $nw=1;
  138.  
  139. $od = opendir($path);
  140. while (false !== ($filename = readdir($od)))
  141. {
  142.     //you can add any type of filenames you wish to skip (for instance Thumbs.db on windows)
  143.     if($filename != '.' && $filename != '..' && !is_dir($path.$filename))
  144.     {
  145.         //we give files a name - here we use increasing numbers for jpg files:
  146.         if(rename($path.$filename, $pathA.$nw++.'.jpg'))
  147.         echo '<br />';
  148.     }
  149. }
  150.  
  151. closedir($od);
  152.  
  153.  
  154. //fill in details about the path
  155. $pathT="uploads/tmp/$userName/t/";
  156. $pathF="uploads/$userName/$albumName/";
  157. //variable used for the name of each file
  158. $nw=1;
  159.  
  160. $odT = opendir($pathT);
  161. while (false !== ($filename = readdir($odT)))
  162. {
  163.     //you can add any type of filenames you wish to skip (for instance Thumbs.db on windows)
  164.     if($filename != '.' && $filename != '..' && !is_dir($pathT.$filename))
  165.     {
  166.         //we give files a name - here we use increasing numbers for jpg files:
  167.         if(rename($pathT.$filename, $pathF.$nw++.'b.jpg'))
  168.         echo '<br />';
  169.     }
  170. }
  171. closedir($odT);
  172.  
  173. $query="INSERT imgUpload (tempID,lastDigit)
  174.  
  175.         VALUES(    
  176.             '$random_digit',
  177.             '$nw')";
  178.  
  179. }
  180.  
  181. $result=mysql_query($query) or die("Error in query:".mysql_error()); 
  182. mysql_close(); 
  183.  
  184. $rmA = "uploads/tmp/$userName/t/";
  185. $rmB = "uploads/tmp/$userName/m/";
  186.  
  187. $mydirA = "$rmA"; 
  188. $d = dir($mydirA); 
  189. while($entry = $d->read()) { 
  190.  if ($entry!= "." && $entry!= "..") { 
  191.  unlink($entry); 
  192.  } 
  193. $d->close(); 
  194. rmdir($mydirA); 
  195.  
  196. $mydirB = "$rmB"; 
  197. $d = dir($mydirB); 
  198. while($entry = $d->read()) { 
  199.  if ($entry!= "." && $entry!= "..") { 
  200.  unlink($entry); 
  201.  } 
  202. $d->close(); 
  203. rmdir($mydirB); 
  204.  
  205. ?>
  206. <script language="JavaScript">
  207. <!--
  208. window.location="<? print $returnURL?>";
  209. //-->
  210. </SCRIPT>
  211. </body>
  212. </html>
  213.  
Jun 5 '10 #1
Share this Question
Share on Google+
2 Replies


P: 2
Hello anfetienne,

Thankyou for posting this script, i would like to implement this to a site. But i am wondering about some of the linked files?

Expand|Select|Wrap|Line Numbers
  1. include('SimpleImage.php');
Is there any chance you could post a zipped folder of all the files needed to run this script successfully :-)

Cheers in advance
John.
Jul 1 '10 #2

anfetienne
100+
P: 424
Please see the attached file for the simpleImahe php script... It is used for the resizing the images.

that is this part of my script

Expand|Select|Wrap|Line Numbers
  1.  $imgSize = getimagesize($add);
  2.  echo $details[0].'<br/>';
  3.  echo $details[1].'<br/>';
  4.  
  5.              if ($imgSize[0] > $imgSize[1]){
  6.              $image = new SimpleImage();
  7.              $image->load("$add");
  8.              $image->resize(450,350);
  9.              $image->save("$add"); 
  10.  
  11.              $image = new SimpleImage();
  12.              $image->load("$tempFLDR");
  13.              $image->resize(100,100);
  14.              $image->save("$tempFLDR"); 
  15.              } 
  16.              elseif ($imgSize[1] > $imgSize[0]) {
  17.              $image = new SimpleImage();
  18.              $image->load("$add");
  19.              $image->resize(240,350);
  20.              $image->save("$add"); 
  21.  
  22.              $image = new SimpleImage();
  23.              $image->load("$tempFLDR");
  24.              $image->resize(100,100);
  25.              $image->save("$tempFLDR"); 
  26.  
@jonnypixel
Attached Files
File Type: zip SimpleImage.zip (1.1 KB, 231 views)
Jul 1 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.