Results 1 to 7 of 7

Thread: PHP File Uploading

  1. #1

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141

    PHP File Uploading

    When I run this code, I get an error saying that userfile_size is undefined. According to the book I am reading, this variable should automaticly be defined,a nd hold the size of the file uploaded. Am I missing something?

    PHP Code:
    <html>
    <head>
    <title>Uploading</title>
    </head>
    <body>
    <h1>Uploading file...</h1>
    <?php
    if ($userfile=="none")
    {
        echo 
    "Problem: no file uploaded";
        exit;
    }
    if (
    $userfile_size==0)
    {
        echo 
    "Problem: uploaded file is zero length";
        exit;
    }
    if (
    $userfile_type != "text/plain")
    {
        echo 
    "Problem: file is not plain text";
        exit;
    }
    $upfile "c:\\".$userfile_name;
    if (!
    copy($userfile$upfile))
    {
        echo 
    "Problem: Could not move file into directory";
        exit;
    }
    echo 
    "File uploaded successfully<br><br>";

    ?>
    </body></html>
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: PHP File Uploading

    Originally posted by blindlizard
    When I run this code, I get an error saying that userfile_size is undefined. According to the book I am reading, this variable should automaticly be defined,a nd hold the size of the file uploaded. Am I missing something?

    I think in order to see what's going on, we'd have to see more. How is the file being selected, where are these variables being created at. Unless I'm missing something, this code shouldn't do much of anything at all.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    scoutt
    Guest
    in your form you have to have an hidden input holding the file size.

    <input type="hidden" name="userfile_size" value="$userfile_size">

  4. #4

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    Here is the page sending the file
    PHP Code:
    <HTML>
    <
    HEAD>
    </
    HEAD>
    <
    BODY>
    <
    form enctype="multipart/form-date" action="test.php" method="post">
    <
    input type="hidden" name="MAX_FILE_SIZE" value="1000">
    <
    INPUT type="file" name="userfile">
    <
    INPUT type="submit" value="Submit" id=submit1 name=submit1>
    </
    form>
    </
    BODY>
    </
    HTML
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  5. #5
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    multipart/form-date

    is that a typo here or in the real page?
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  6. #6

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    Oh my God!!! that has to be it......Thanks
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  7. #7

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141

    Talking

    That worked, thank you. I knew it should not be that difficult to upload in PHP!
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

Posting Permissions

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



Click Here to Expand Forum to Full Width