PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 23rd, 2005, 01:55 AM
wai wai is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 wai User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy File upload problem?

Hi,

I got a problem of file upload. anybody can help?
I just copy the code from php.net, but it still can't work. anybody can help? Thanks!


The HTML FORM as below:

<html><head></head><body>
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="test.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
</body></html>

The PHP as below:
<html><head></head><body><?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
//if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?> </body></html>

I tried to run the code, the result is:

Possible file upload attack!
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => pires.gif
[type] => image/gif
[tmp_name] => /tmp/phphR5y14
[error] => 0
[size] => 5735
)

)

Then, i tried to replace by a "is_upload_file". Result is okay as below, however, i can't find any "php4vph5i" files upload to /tmp directory.

File is valid, and was successfully uploaded.
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => pires.gif
[type] => image/gif
[tmp_name] => /tmp/php4vph5i
[error] => 0
[size] => 5735
)

)

So, anybody knows the problem caused? I have already set the php.ini as below.

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = /tmp

; Maximum allowed size for uploaded files.
upload_max_filesize = 2M


My php version is "4.3.10", apache is "2.0.51", running under the fedora 2.

Thanks for your kindly help! Wai

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > File upload problem?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT