Current location: Hot Scripts Forums » Programming Languages » PHP » Upload script having prob with possible upload attack


Upload script having prob with possible upload attack

Reply
  #1 (permalink)  
Old 12-13-03, 11:16 PM
Lexmx Lexmx is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Question Upload script having prob with possible upload attack

hi sorry about this but i am trying to have a php script which will upload files as all of you know some work and some just dont work well all the 1's i have found all have the same problem of uploading music, they crash or tell me it a possible upload attack here my script so can u tell me wat to do to stop this and allow my music to b uploaded

----------------------------------------------------------------------
<?php
// $userfile is where file went on webserver
$userfile = $HTTP_POST_FILES['userfile']['tmp_name'];
// $userfile_name is original file name
$userfile_name = $HTTP_POST_FILES['userfile']['name'];
// $userfile_size is size in bytes
$userfile_size = $HTTP_POST_FILES['userfile']['size'];
// $userfile_type is mime type e.g. image/gif
$userfile_type = $HTTP_POST_FILES['userfile']['type'];
// $userfile_error is any error encountered
$userfile_error = $HTTP_POST_FILES['userfile']['error'];

// userfile_error was introduced at PHP 4.2.0
// use this code with newer versions

if ($userfile_error > 0) {
echo 'Problem: ';
switch ($userfile_error)
{ case 1:
echo 'File exceeded upload_max_filesize';
break;
case 2:
echo 'File exceeded max_file_size';
break;
case 3:
echo 'File only partially uploaded';
break;
case 4:
echo 'No file uploaded';
break;
}
exit;
}

// put the file where we'd like it
$upfile = '/uploads/'.$userfile_name;

// is_uploaded_file and move_uploaded_file
if (is_uploaded_file($userfile))
{
if (!move_uploaded_file($userfile, $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
}
} else {
echo 'Problem: Possible file upload attack. Filename: '.$userfile_name;
exit;
}
echo 'File uploaded successfully<br /><br />';

// show what was uploaded
echo 'Preview of uploaded file contents:<br /><hr />';
echo $contents;
echo '<br /><hr />';
?>
----------------------------------------------------------------------
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 01:12 AM
upload script cabj1981 PHP 43 03-04-04 04:19 PM
Need an upload revision ebay script that works well. fooleo Job Offers & Assistance 0 12-07-03 08:21 PM
Help with my upload script TheMetsAreBad PHP 2 12-04-03 07:10 PM
What to watch when implementing an upload script johno PHP 0 11-21-03 08:00 PM


All times are GMT -5. The time now is 01:39 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.