473,383 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

how to implement uploadify with my own custom upload.php

anfetienne
424 256MB
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
2 4121
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
424 256MB
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, 242 views)
Jul 1 '10 #3

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

Similar topics

1
by: Ron Provost | last post by:
Hello, I've written a simple GUI which contains a listbox to hold some information. I've found that the click-selection schemes provided by Tkinter are insufficient for my needs. Essentiall I...
4
by: drewnoakes | last post by:
Hi, I'm developing an application server to which clients will connect over the network. This server has a variety of entry points, and remoting seems well suited for those clients written in...
3
by: Clint | last post by:
Hi, I am trying to implement the custom paging in the datalist in this format: << Prev 1,2,3,4,5 Next >>. Does anyone knows how to do this. Thanks in advance. Clint
6
by: Shimon Sim | last post by:
Hi I am working on application that need to hold custom user information - Last and first name, email, some other domain related information. I used to create Base class for all my pages. The base...
1
by: Marko Vuksanovic | last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is...
6
by: Marko Vuksanovic | last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is...
1
by: Todd Beaulieu | last post by:
I need to return a reference of a server-side object to the client. I want that class to implement a custom interface (there will be a number of classes involved here and they will all support the...
10
karlr
by: karlr | last post by:
OK, I know this has been discussed in multiple posts. However, I still have not seen a good example. That is, I have a custom Membership provider using the ASP.NET 2.0 controls. I am restricted...
5
by: John Devlon | last post by:
Hi, Some people like to go on vacation during christmas time, others try to do something they never did before.... I would like to create a multiple file upload page, with some nice progress...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.