Welcome to WebmasterWorld Guest from 23.22.46.195

Forum Moderators: coopster & jatar k

$ FILES['uploadedfile']['tmp name'] is empty

$_FILES['uploadedfile']['tmp_name'] is empty after user uploads a file

   
9:23 am on Mar 16, 2009 (gmt 0)

5+ Year Member



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!

10:02 am on Mar 16, 2009 (gmt 0)

5+ Year Member



Check if php.ini has file uploads enabled:

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

; Whether to allow HTTP file uploads.
file_uploads = On

10:11 am on Mar 16, 2009 (gmt 0)

5+ Year Member



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!

11:52 am on Mar 16, 2009 (gmt 0)

10+ Year Member



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 ?>"> 
12:05 pm on Mar 16, 2009 (gmt 0)

5+ Year Member



no way! I'm surely blind :) thanks a bunch!
4:01 pm on Mar 17, 2009 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



The enctype is usually it, now that you've solved that Google for "$PHP_SELF vulnerability" and change the form action. :-)
3:23 am on Mar 18, 2009 (gmt 0)

5+ Year Member



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!
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month