473,399 Members | 4,192 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,399 software developers and data experts.

how to use your own upload.php script with uploadify

I was just wondering if you ever figured out how to use your own upload.php script with uploadify? If so, could you explain how you got it to work? here is the script I would like to use with uploadify:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   if (isset($_POST['upload'])) {
  3.   $con = mysql_connect("localhost", "sbslogin", "sbsdatab@53!") or die("cannot connect");
  4.   mysql_select_db("sbsdat", $con) or die("cannot select DB");
  5.       $img = $_FILES["image"]["name"];
  6.       foreach ($img as $key => $value) {
  7.           $name = $_FILES["image"]["name"][$key];
  8.           $tname = $_FILES["image"]["tmp_name"][$key];
  9.           $size = $_FILES["image"]["size"][$key];
  10.           $oext = getExtention($name);
  11.           $ext = strtolower($oext);
  12.           $base_name = "uploads/".getBaseName($name).".$ext";
  13.        $whois = $_SERVER['REMOTE_ADDR'];
  14.           if ($ext == "jpg" || $ext == "jpeg" || $ext == "bmp" || $ext == "gif") {
  15.               if ($size < 1024 * 1024) {
  16.                   if (file_exists("uploads/" . $name)) {
  17.                       move_uploaded_file($tname, "uploads/" . $name);
  18.                       $result = 1;
  19.                       //list($width, $height) = getimagesize("uploads/" . $name);
  20.                       $qry = "select id from img where img_base_name='$base_name' and img_ext='$ext'";
  21.                       $res = mysql_fetch_array(mysql_query($qry));
  22.                       $id = $res['id'];
  23.                       $qry = "UPDATE pictures SET path='$base_name', type='$ext', size='$size', date=NOW() where id=$id";
  24.                       mysql_query($qry);
  25.                       ?><div style="float:right; text-align:left; width:400px;"><?php echo "Image '$name' <font color='blue'>updated</font><br />";
  26.                   } else {
  27.                       move_uploaded_file($tname, "uploads/" . $name);
  28.                       $result = 1;
  29.                       //list($width, $height) = getimagesize("uploads/" . $name);
  30.                       $qry = "INSERT INTO pictures(id, path, type, size, email, whois, date) VALUES ('', '$base_name', '$ext', '$size', 'd.schuett@gmail.com', '$whois', NOW())";
  31.                       mysql_query($qry, $con);
  32.                       //Error Checking off by default. Uncomment if you run into problems.
  33.                       //mysql_error();
  34.                       //print_r($qry);
  35.                       ?><div style="float:right; text-align:left; width:400px;"><?php echo "Image '$name' <font color='green'>uploaded</font><br />";
  36.                   }
  37.               } else { 
  38.                   ?><div style="float:right; text-align:left width:400px;"><?php echo "<font color='red'><B>Image size excedded.<br />File size should be less than 1Mb</B></font><br />";
  39.               }
  40.           } else {
  41.               ?><div style="float:right; text-align:left; width:400px;"><?php  echo "<font color='red'><B>Invalid file extention '.$oext'</B></font><br />";
  42.           }
  43.       }
  44.   }
  45.   function getExtention($image_name)
  46.   {
  47.       return substr($image_name, strrpos($image_name, '.') + 1);
  48.   }
  49.   function getBaseName($image_name)
  50.   {
  51.       return substr($image_name, 0, strrpos($image_name, '.'));
  52.   }
  53. ?>
  54.  
Oct 10 '10 #1
2 3295
oranoos3000
107 100+
hi
you must add a form to the page and sumbit attritue of this form you must be add address of this file ,
$_FILES[NAME] , NAME is the name attribute of the file element in this form ,
in this script extension file is check, size of the file is checked ,... and otherwise any disobey this conditional file is uploaded and after upload path of the file is saved on the database

for more details , study chapter file upload in php
thanks alot
Oct 10 '10 #2
anfetienne
424 256MB
hi dana,

I intergrated my own upload script with the one that came with uploadify... it was the easiest way and because uploadify looks for certain vars it was a pain to use my complete own so i had to mix the two as simple as possible as well due to the fact that uploadify kept on messing up on me... below is the code i used, it's not the answer you are looking for as I wrote this for a social networking script... there really isn't much to explain apart from i upload to a temp folder change the image sizes then rename and move the images to the correct folder, the majority of it is still uploadify's standard script

Expand|Select|Wrap|Line Numbers
  1. $userPhoto=mkdir('user/'.$userName.'/photos/'.$uploadID.'/', 0777);
  2. $userTemp=mkdir('user/'.$userName.'/photos/'.$uploadID.'/tmp/', 0777); 
  3. $userThumb=mkdir('user/'.$userName.'/photos/'.$uploadID.'/tmp/t/', 0777); 
  4. $userMain=mkdir('user/'.$userName.'/photos/'.$uploadID.'/tmp/l/', 0777); 
  5. //    specify file parameter name
  6. $file_param_name = 'file';
  7. //    retrieve uploaded file name
  8. $file_name = $_FILES[ $file_param_name ][ 'name' ];
  9. //    retrieve uploaded file path (temporary stored by php engine)
  10. $source_file_path = $_FILES[ $file_param_name ][ 'tmp_name' ];
  11. //    construct target file path (desired location of uploaded file) -
  12. //    here we put to the web server document root (i.e. '/home/wwwroot')
  13. //    using user supplied file name
  14. if (isset($userName)){
  15.     $target_file_path = "user/".$userName ."/photos/". $uploadID . "/tmp/l/" . $file_name;
  16. } else {
  17.     $target_file_path = "user/" . $file_name;
  18. }
  19. //    move uploaded file
  20. if( move_uploaded_file( $source_file_path, $target_file_path ) ) {    
  21. $pathA = "user/".$userName ."/photos/". $uploadID . "/tmp/l/";
  22. $pathB = "user/".$userName ."/photos/". $uploadID . "/tmp/t/";
  23. if ($handle = opendir($pathA)) {
  24.        while (false !== ($file = readdir($handle))) {
  25.         if ($file != "." && $file != "..") {
  26.             if(!is_dir($file)){
  27.                 $source = $pathA . $file;
  28.                 $destination = $pathB . $file;
  29.                 copy($source, $destination);        
  30.  $details = array();
  31.  $details = getimagesize($source);
  32.  $detailsWidth = $details[0];
  33.  $detailsHeight = $details[1];
  34.              if ($detailsWidth > $detailsHeight){
  35.              $image = new SimpleImage();
  36.              $image->load("$source");
  37.              $image->resize(450,350);
  38.              $image->save("$source");
  39.  
  40.              $image = new SimpleImage();
  41.              $image->load("$destination");
  42.              $image->resize(100,70);
  43.              $image->save("$destination"); 
  44.              } 
  45.              elseif ($detailsHeight > $detailsWidth) {
  46.              $image = new SimpleImage();
  47.              $image->load("$source");
  48.              $image->resize(240,350);
  49.              $image->save("$source"); 
  50.  
  51.              $image = new SimpleImage();
  52.              $image->load("$destination");
  53.              $image->resize(70,100);
  54.              $image->save("$destination"); 
  55.              }
  56.             }
  57.         }
  58.  
  59.        } closedir($handle);       
  60. }
  61. }
  62. //variable used for the name of each file
  63. $rnA = "user/".$userName ."/photos/". $uploadID . "/tmp/l/";
  64. $rnB = "user/".$userName ."/photos/". $uploadID . "/";
  65. $od = opendir($rnA);
  66. while (false !== ($filename = readdir($od)))
  67. {
  68.     //you can add any type of filenames you wish to skip (for instance Thumbs.db on windows)
  69.     if($filename != '.' && $filename != '..' && !is_dir($rnA.$filename))
  70.     {
  71.         //we give files a name - here we use increasing numbers for jpg files:   '_'.$i++.'
  72.         if(rename($rnA.$filename, $rnB.$uploadID.zonedate('dmYH-i-s',true).'.jpg'))
  73.         echo '<br />';
  74.     }
  75. }
  76. closedir($od);
  77. $rnC = "user/".$userName ."/photos/". $uploadID . "/tmp/t/";
  78. $rnD = "user/".$userName ."/photos/". $uploadID . "/";
  79. $odT = opendir($rnC);
  80. while (false !== ($filename = readdir($odT)))
  81. {
  82.     //you can add any type of filenames you wish to skip (for instance Thumbs.db on windows)
  83.     if($filename != '.' && $filename != '..' && !is_dir($rnC.$filename))
  84.     {
  85.         //we give files a name - here we use increasing numbers for jpg files:   '_'.$i++.'
  86.         if(rename($rnC.$filename, $rnD.$uploadID.zonedate('dmYH-i-s',true).'_'.'b.jpg'))
  87.         echo '<br />';
  88.     }
  89. }
  90. closedir($odT);
  91.  
Oct 11 '10 #3

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

Similar topics

2
by: lawrence | last post by:
The following upload script seems to be working on PCs but not on Macs. Can anyone imagine a reason why? Could there be something in the form that turns in flawed data, or could IE on a Mac not...
1
by: Sielvja | last post by:
Hi, i've put an upload script on my site, hosted on a Windows NT Version 5.0 server. When i try to upload something i get an error: copy(files/file.txt): failed to open stream: Permission...
2
by: Willoughby Bridge | last post by:
I am having trouble with a file upload script. Have tried a lot of different methods and the problem boils down to the $_FILES variable not being picked up. Below is a simple example of...
2
by: Chuck | last post by:
Hi, can anyone provide or point me in the direction of a simple python file upload script? I've got the HTML form part going but simply putting the file in a directory on the server is what I'm...
4
by: brian.digipimp | last post by:
So I wrote this upload script and I keep getting errors and can't get it to work. I'm running ubuntu linux and here is my code: <html> <head> <title>Upload</title> </head> <body> <?php
2
by: grozanc | last post by:
Hello, I keep getting the following erorrs when trying to use a PHP/MYSQL upload script. Can anyone tell me what's causing this error? I'm not a programmer, just an MFA student working on his...
3
by: Ken1 | last post by:
Hello, Does anyone know of an easy to implement ajax upload script for php which also has a progress bar. If possible I'd like it to be able to remove already uploaded files and do minor...
5
by: camphor | last post by:
hi, I have found an upload script in hotscripts and have implemented it into the website, I followed the installation steps to 'give write permissions to php on the upload folder (which is...
0
by: ll | last post by:
I'm working with 'pure ASP upload' script which is designed to redirect to an alert/error message, should a file larger than the set limit be attempted to be uploaded. The problem is that, while...
5
by: petershaman | last post by:
Hi I have a gorgeous flash image gallery, it would work perfectly fine but there's a small problem I can't upload anything thru it's upload script, since I'm getting an error 403. It's so because...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.