homepage Welcome to WebmasterWorld Guest from 54.146.175.204
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
$ FILES['uploadedfile']['tmp name'] is empty
$_FILES['uploadedfile']['tmp_name'] is empty after user uploads a file
nil111

5+ Year Member



 
Msg#: 3871245 posted 9:23 am on Mar 16, 2009 (gmt 0)

my form to upload files(without designing code):
[HTML]
<form method="post" name="form1" id="form1" action="<?php $PHP_SELF ?>">

<input name="frm_title" type="text" id="frm_title" size="50" />

<input type="file" id="uploadedfile" name="uploadedfile"/>

<textarea name="frm_desc" id="frm_desc" cols="47" rows="5"></textarea>

<input name="form_posted" type="hidden" value="true" />

<input name="btn_save" type="submit" class="bg-blue" value="Save and Continue" />
</form>
[END OF HTML]

code to capture the posted data:

[PHP]
<?php
if(isset($_POST['form_posted'])){
$query = "insert into latest_news_tb(title,description)values('$_POST[frm_title]','$_POST[frm_desc]')";
$db = new Database();
$return_id = $db->query_mysql_insert_id($query);

$target_path = "../media_centre/images_media/";
$target_path = $target_path."LN".$return_id.".jpg";

$name = $_FILES['uploadedfile']['tmp_name'];
print $name;
print_r($_FILES);

//if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
//print 'file uploaded';
//}
?>
[END OF PHP]

here I'm trying to upload the file. but $_FILES['uploadedfile']['tmp_name'] is empty. why is that?

gettin the $return_id works fine.

tried the following:

1.upload a tiny image to see whether the problem was with the MAX_FILE_SIZE
2.made the folder file permissions to 777.
3. the disk also have enough space

so,

how is this possible?

even the $_FILES['uploadedfile']['name'], $_FILES['uploadedfile']['size'] is empty.

Thanks in advance!

 

Jsyvanne

5+ Year Member



 
Msg#: 3871245 posted 10:02 am on Mar 16, 2009 (gmt 0)

Check if php.ini has file uploads enabled:

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

; Whether to allow HTTP file uploads.
file_uploads = On

nil111

5+ Year Member



 
Msg#: 3871245 posted 10:11 am on Mar 16, 2009 (gmt 0)

thanks for the reply. the php.ini is :

;;;;;;;;;;;;;;;;
; 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 =

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

well the other uploading parts are working well too. sigh sigh!

sonjay

10+ Year Member



 
Msg#: 3871245 posted 11:52 am on Mar 16, 2009 (gmt 0)

Your form tag needs to include enctype="multipart/form-data":

<form method="post" name="form1" id="form1" enctype="multipart/form-data" action="<?php $PHP_SELF ?>">

nil111

5+ Year Member



 
Msg#: 3871245 posted 12:05 pm on Mar 16, 2009 (gmt 0)

no way! I'm surely blind :) thanks a bunch!

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3871245 posted 4:01 pm on Mar 17, 2009 (gmt 0)

The enctype is usually it, now that you've solved that Google for "$PHP_SELF vulnerability" and change the form action. :-)

nil111

5+ Year Member



 
Msg#: 3871245 posted 3:23 am on Mar 18, 2009 (gmt 0)

it works just fine. my original question was solved. n thanks to Sonjay for that!
As why change $PHP_SELF? you mean to specify the page name like "sample.php" instead?
wil have a look thanks rocknbil!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved