SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Texas
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    multiple file upload script.

    I'm trying to write a little script for someone to upload multiple files into a directory they can create through this script. When I try to run the script it just runs real slow and doesn't do anything. Does anyone see anything wrong with it?

    view it at http://www.magicscripts.net/test2/source.php

    ok, I got it somewhat working, it uploads the files but if I upload less then 4 files its tying to upload all 4 files still and pop up with an error.
    Last edited by magicscripts; Aug 2, 2001 at 15:21.
    Mark -
    www.magicscripts.net

  2. #2
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I would use client side checking to see if all four files are present. And if they aren't execute certain parts of script....

  3. #3
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about just

    if ($file1) { upload($file1); }
    if ($file2) { upload($file1); }
    if ($file3) { upload($file1); }
    if ($file4) { upload($file1); }

  4. #4
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I made such a script a few days ago too, I'll post it here, maybe you can use some parts of it, especially the looping thing
    (remember not just to copy/past from this forum, but after that replacing the spaces with normal spaces...)

    PHP Code:
    /*****************************************/
    //                upload                
    /*****************************************/

    if($upload
    {
        for(
    $num=1;$num<6;$num++) 
        {
            
    $picture "fileup$num"."_name";
            
    $picture1 = $$picture;
            
    $picture2 "fileup$num";
            
    $picture3 = $$picture2;
            
            if(
    $picture3
            {    
                
    $filesizebytes filesize($picture3);

                
    //control structure
                
    if($filesizebytes 1048576)
                {
                    
    $output .= "Error uploading: File size for file $num is too big.<br>";
                }
                elseif(
    file_exists("/path_here/$picture1")) $output .="Error uploading: File name already exists for file $num<br>";
                
                
    //file is ready to upload...
                
    else 
                {
                    
    copy ($picture3"/path_here/$picture1");
                    
    $output .="$picture1<br>";
                }
            }
        }

        if(!
    $output$output .= "Error uploading: No files have been selected for upload";

        echo(
    "<b>Uploaded files:<br> <i>$output</i></b>");
    }

    /*****************************************/
    //            form upload
    /*****************************************/

        //opera can't upload
        
    if(stristr($HTTP_USER_AGENT"opera"))print "<b>Sorry, but you are not able to use the upload form with Opera as brower.  This is due to a bug in Opera.</b>";
        else
        {
            print 
    "<form enctype=\"multipart/form-data\" action=\"$PHP_SELF\" method=\"post\">\n".
                    
    "<b>Add Graphics</b><br>\n";
                   for(
    $num=1;$num<6;$num++)
                        {
                            print 
    "file $num:<input name=\"fileup$num\" type=\"file\"><br>\n";
                        }
                    
            print 
    "<br><input name=\"doupload\" type=\"submit\" value=\"Upload files\"></form><br>\n";
        } 
    hope this helps you a bit? you can add more control structures though, but in my case only core members can use this form, so nobody will upload his divX's on the server
    Last edited by =X=; Aug 3, 2001 at 02:49.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •