Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Upload script

  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Upload script

    I need to upload text file from the local machine to the server. The problem is I'm getting only file name, but not the contents. Here is my script:

    PHP Code:
    printf("<TABLE>\n");    

    printf("  <TD NOWRAP>\n");


    printf("   <FORM NAME=\"UplForm\" METHOD=\"POST\" ENCTYPE=\"multipart/form-data\" ACTION=\"upload.php\" AUTOCOMPLETE=off>\n");    

    printf("  <TD>\n");
    printf("    File to upload:\n");
    printf("  </TD>\n");
    printf("  <TD>\n");

    printf("    <INPUT TYPE=file ACCEPT=\"text/plain\" NAME=\"upfile\"  SIZE=\"40\" VALUE=\"Browse\">\n");


    printf("  </TD>\n");    
    printf("</TABLE>\n");            
    printf("    <INPUT TYPE=submit VALUE=\"Upload file:\">\n");        

    printf("   </FORM>\n"); 
    And all I get in the upload.php script is $upfile = “filename.txt”.
    All functions like filesize, file_exists return nothing.

    What I'm doing wrong?

  • #2
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Wrapping all that stuff in printf is a waste of resources and your HTML is kind of a mess, but the PHP part looks ok.

    Eg., I changed this to post to itself and added the little snip at the end:
    PHP Code:
    <FORM NAME="UplForm" METHOD="POST" ENCTYPE="multipart/form-data" ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" AUTOCOMPLETE=off>
    <TABLE>        
        <TD>
            File to upload:
        </TD>
        <TD>
            <INPUT TYPE=file ACCEPT="text/plain" NAME="upfile"  SIZE="40" VALUE="Browse">
        </TD>    
    </TABLE>            
        <INPUT TYPE=submit VALUE="Upload file:">        
    </FORM>
    <?php
    if (isset($_FILES['upfile']))
    {
        
    print_r($_FILES['upfile']);
    }
    ?>
    and I get:
    Code:
    Array
    (
        [name] => some.file    // the name of the file on the uploader's computer
        [type] => application/octet-stream
        [tmp_name] => /tmp/php2A8.tmp // the actual file name on disc until you use move_uploaded_file() on it
        [error] => 0
        [size] => 455
    )

  • #3
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ralph l mayo
    Wrapping all that stuff in printf is a waste of resources and your HTML is kind of a mess, but the PHP part looks ok.

    Eg., I changed this to post to itself and added the little snip at the end:
    PHP Code:
    <FORM NAME="UplForm" METHOD="POST" ENCTYPE="multipart/form-data" ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" AUTOCOMPLETE=off>
    <TABLE>        
        <TD>
            File to upload:
        </TD>
        <TD>
            <INPUT TYPE=file ACCEPT="text/plain" NAME="upfile"  SIZE="40" http://www.codingforums.com/newreply.php?do=newreply&p=410339VALUE="Browse">
        </TD>    
    </TABLE>            
        <INPUT TYPE=submit VALUE="Upload file:">        
    </FORM>
    <?php
    if (isset($_FILES['upfile']))
    {
        
    print_r($_FILES['upfile']);
    }
    ?>
    and I get:
    Code:
    Array
    (
        [name] => some.file    // the name of the file on the uploader's computer
        [type] => application/octet-stream
        [tmp_name] => /tmp/php2A8.tmp // the actual file name on disc until you use move_uploaded_file() on it
        [error] => 0
        [size] => 455
    )
    Big thnx!

  • #4
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    845
    Thanks
    15
    Thanked 10 Times in 10 Posts
    Edit.... Sorry... replyed when I wanted a new one... <_<
    Last edited by dniwebdesign; 03-02-2006 at 08:32 AM.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.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
    •