SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Get File Size

  1. #1
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    Berlin
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get File Size

    Hi,

    I don't know much about JavaScript, but I think I need it to calculate the filesize of a file on a client computer.

    I want a user to choose a file he wants to upload and the JavaScript to get the Size of this file automatically - or if it is the only way with a " get file size" button - and insert it into the field "filesize".

    PHP Code:
    <form id="FormName" action="" method="get" name="upload">
                
    <
    input type="file" name="fileGetterName" size="16"><br/><br/>

    <
    input type="text" name="filesize" size="24">
    <
    input type="button" value="get file size"><br/><br/>
                
    <
    input type="submit" name="submitButtonName">
            </
    form
    Can anybody help me with such a JavaScript. I couldn't find a Script, that does it by now and I don't have an Idea how to get the value of a JavaScript into a field...



    Thanks
    Fl÷zen

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Los Angeles
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately, you can't do this with just Javascript because of security reasons regarding accessing local files. For more information, see:

    http://www.sitepoint.com/forums/showthread.php?t=134187

    The best way to do it is on the server side or via an ActiveX control if you only want to support IE (groan).

  3. #3
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    Berlin
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was afraid that someone would give me this answer

    How can I get the file size of an file on the client's (user's) computer with a server side script???

    The thing I wanted to do is following:
    When normal users try to upload a file, they will close their browser-window after hitting the upload button - thus nothing is uploaded - they dont understnad, that it takes some time to upload 5MB.
    Even if you write in red letters 50px: The upload is done, when it is told... or something like this.

    Thus I thought to write an JavaScript, that fills in automatically the Size of a file into a field, which is submitted to the server. The server compares the expected filesize with the already uploaded filesize und returns an information to the user, which tells him how may percent are already uploaded....

    Thus I guess, ther is no way to tell someone how long his upload will take and (!) how many percentage are already uploaded. Unless the user is smar enough to enter the filesize by himself

    Thanks anyway
    Fl÷zen

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Los Angeles
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you can't really do what you described above with a server side script either since the server side script would only tell you the file size after the upload finished.

    What I suggest is that you make an animated upload graphic (something similar to what Windows does when you move large amounts of files around with the flying file folders). When the upload is complete, stop the animation and replace it with an "Upload Complete" message. This should hopefully visually indicate that there's an upload in progress and the user shouldn't close the window.

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your question doesn't make much sense. You say that prompting users to wait for the upload to complete - even in red letters 50px high - won't be effective...why would showing a progress bar/meter/legend make a difference?

    You can easily pop up a small window with a loading message or animation, and close it when the process is complete. Most users should notice that
    ::: certified wild guess :::

  6. #6
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    Berlin
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It sure makes sense

    An Animation would be one possibility, but it would be better to show the progress of uploading.
    When uploading a 5MB file and nothing seems to happen, you get unsure if the upload is working at all.... - im not sure if an simple animatation would help?!

    Fl÷zen

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Los Angeles
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For an example, check out the way Yahoo does the file upload for their Briefcase service (http://briefcase.yahoo.com).


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
  •