Do not use on any
shared computer
July 25, 2008 05:46pm pdt
null
[x]
Attachment Details

very simple file upload script for multiple files

Tags: upload, php, multiple, script, file
I need an upload script that will upload multiple files at once.  I need to set the file names to be the same everytime.  So it renames the files after uploading.  I need to upload 5-10 files and have them automatically named 1.gif through 10.gif.   I have a couple of scripts that do this fine for one file at a time but I need to do multiple for a slide show.

Thanks-

Heres what I use now.  If I could some how use a meta refresh after submitting.  

Thanks-

<?php

$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this =  "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

$upload_dir = "../images/";
$upload_url = "http://####";
$message ="";

//create upload_files directory if not exist
//If it does not work, create on your own and change permission.
if (!is_dir("images")) {
      die ("upload_files directory doesn't exist");
}

if ($_FILES['userfile']) {
      $message = do_upload($upload_dir, $upload_url);
}
else {
      $message = "Invalid File Specified. Ignore if you havent clicked upload yet";
}

print $message;

function do_upload($upload_dir, $upload_url) {

      $temp_name = $_FILES['userfile']['tmp_name'];
      $file_name = '1.gif';
      $file_type = $_FILES['userfile']['type'];
      $file_size = $_FILES['userfile']['size'];
      $result    = $_FILES['userfile']['error'];
      $file_url  = $upload_url.$file_name;
      $file_path = $upload_dir.$file_name;

      //File Name Check
    if ( $file_name =="") {
          $message = "Invalid File Name Specified";
          return $message;
    }
    //File Size Check
    else if ( $file_size > 500000) {
        $message = "The file size is over 500K.";
        return $message;
    }
    //File Type Check
    else if ( $file_type == "text/plain" ) {
        $message = "Sorry, You cannot upload any script file" ;
        return $message;
    }

    $result  =  move_uploaded_file($temp_name, $file_path);
    $message = ($result)?"File url <a href=$file_url>$file_url</a><br><img src=$file_url height=\"210\" width=\"210\">" :
                "Somthing is wrong with uploading a file.";

    return $message;
}
?>
<style type="text/css">
<!--
.style1 {
      font-family: Verdana, Arial, Helvetica, sans-serif;
      font-weight: bold;
}
.style2 {font-family: Verdana, Arial, Helvetica, sans-serif}
-->
</style>

<title>Slideshow Upload Page</title><form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
  <span class="style1">Upload Slideshow Image<br>
  </span>  
  <input type="file" id="userfile" name="userfile"><br>
  <input type="submit" name="upload" value="Upload">
</form>
<p class="style2">Click Browse to choose the slideshow file (1.gif) on your computer or office network.</p>
<p class="style2">Click Upload</p>
<p class="style2">The image displayed will be in the slideshow on the front page of lulushoponline </p>
<p class="style2"><a href="collage_upload.php">Change Collage Picture</a></p>
<p class="style2"><a href="slideshow_upload.php">Change Slideshow Image</a></p>
<p><span class="style2"><a href="featured_upload.php">Change Featured Items</a></span> </p>
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Web Development
Question Asked By: livegirllove
Solution Provided By: peyox
Participating Experts: 4
Solution Grade: A
Views: 684
Translate:
Loading Advertisement...
 
[+][-]Assisted Solution by hernst42

Rank: Genius

Assisted Solution by hernst42:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by peyox
Accepted Solution by peyox:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by hernst42

Rank: Genius

Expert Comment by hernst42:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by livegirllove
Author Comment by livegirllove:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Administrative Comment by CetusMOD
Administrative Comment by CetusMOD:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by SabreCEO
Expert Comment by SabreCEO:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by livegirllove
Author Comment by livegirllove:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by mbigrad
Expert Comment by mbigrad:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by livegirllove
Author Comment by livegirllove:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34