#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Beijing,China
    Posts
    17
    Rep Power
    0
    I use the following code to upload files:
    <form action="upload.php3" method=post>
    <input type="file" name="userfile" size="35" value="Browse.."><br>
    <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="100000">
    ....................name="userfile2" .....
    ....................name="userfile3" .....
    </form>

    //upload.php3
    if($userfile!="" && $userfile!="none")
    {
    if(copy($userfile,$userfile_name))
    { echo $MAX_FILE_SIZE;
    echo $userfile_size;
    }
    }
    ............
    The varible $userfile_size becomes available just after the copy() function's finished. right?
    but if i want to get the total size of 3 or more files and decide whether upload them or not,how can i do?
    Thanks!

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Washington, USA
    Posts
    52
    Rep Power
    14
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>The varible $userfile_size becomes available just after the copy() function's finished. right?[/quote]

    Wrong. You can check it before you actually copy it over with something like this:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    if(($userfile1_size + $userfile2_size + $userfile3_size) < 300000) {
    // now we can copy because all 3 fileuploads are less than 293 K
    } else {
    $in_k = 300000 / 1024; // convert size from bytes to K
    echo("Sorry, all uploaded files cannot be larger than <b>$in_k k</b> in size. Please reduce filesize and upload again.");
    }
    [/code]


    ------------------
    <UL TYPE=SQUARE>
    <LI> TD Scripts
    <LI> Script School
    <LI>php-scripts
    </UL>
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Gig Harbor, Washington, USA
    Posts
    29
    Rep Power
    0
    Ahhh damnit TDavid, I was about to make myself feel good by helping instead of asking for once Hehe, I just did an uploading script yesterday.

    The way he did it is the way I did it.. so.. listen to him.

    ------------------
    chris swanicke
    swanicke@defected.net
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Beijing,China
    Posts
    17
    Rep Power
    0
    Great! That's what i want.Thand u!
    I have another quesion:
    what is the max value of $MAX_FILE_SIZE? And it can really prevent you uploading big files?
    I tried to change the value of $MAX_FILE_SIZE,and uploaded a big file ,finding the computer dead!
  8. #5
  9. No Profile Picture
    perspiration
    Guest
    Devshed Newbie (0 - 499 posts)
    In response to TDavid's comment about being able to determine file size BEFORE copying the file:

    Note that there are two stages to the process:
    1. The file being automatically uploaded to the temp directory (which initiates when the user clicks the submit button on the form containing the file-to-upload details)
    2. Your code deciding to copy it from the temp directory to your own directory for processing/validation.

    So yes, you can determine file size (and other info) before stage 2, but I don't believe you can determine file size before stage 1 has completed (unfortunately).

    I'd love to proven wrong - if a user wants to upload a 10Mb file I'd much prefer to prevent them doing this with a clean error message BEFORE stage 1 gets under way. But I don't think this is possible.

    Any takers? Fingers crossed.

Similar Threads

  1. Replies: 1
    Last Post: February 8th, 2004, 01:59 PM
  2. Replies: 1
    Last Post: January 31st, 2004, 03:11 PM
  3. Uploaded files get 644 permision
    By bogaa in forum PHP Development
    Replies: 5
    Last Post: January 27th, 2004, 12:50 PM
  4. Previewing uploaded files before storing
    By rodina in forum PHP Development
    Replies: 0
    Last Post: January 15th, 2004, 01:33 AM
  5. file uploading.. 0 file(s) uploaded
    By zingzee in forum Java Help
    Replies: 1
    Last Post: December 16th, 2003, 08:51 AM

IMN logo majestic logo threadwatch logo seochat tools logo