Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-15-2006, 01:15 PM   PM User | #1
fikka
New to the CF scene

 
Join Date: Jul 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
fikka is an unknown quantity at this point
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?
fikka is offline   Reply With Quote
Old 02-15-2006, 09:32 PM   PM User | #2
ralph l mayo
Regular Coder

 
ralph l mayo's Avatar
 
Join Date: Nov 2005
Posts: 951
Thanks: 1
Thanked 31 Times in 29 Posts
ralph l mayo is on a distinguished road
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
)
ralph l mayo is offline   Reply With Quote
Old 02-16-2006, 03:21 PM   PM User | #3
fikka
New to the CF scene

 
Join Date: Jul 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
fikka is an unknown quantity at this point
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!
fikka is offline   Reply With Quote
Old 03-02-2006, 07:57 AM   PM User | #4
dniwebdesign
Regular Coder

 
dniwebdesign's Avatar
 
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
dniwebdesign is an unknown quantity at this point
Edit.... Sorry... replyed when I wanted a new one... <_<
__________________
Dawson Irvine
CEO - DNI Web Design
http://www.dniwebdesign.com

Last edited by dniwebdesign; 03-02-2006 at 08:32 AM..
dniwebdesign is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:14 PM.


Advertisement
Log in to turn off these ads.