Follow us on Twitter!
Understanding is the answer, hatred is the problem, and hackers are the slaves abused and destroyed in the process of peace online - Deshouleres
Thursday, April 24, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 15
Guests Online: 14
Members Online: 1

Registered Members: 82890
Newest Member: ByteofPython
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

PHP mime types issue


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-01-09 21:36
Trying to make an uploader for a project and set it to only allow .mp3's, so I went with mime types and it still thinks that the uploaded file is never an mp3, even with the correct mime type.

(I know the upload limit is small, there's a reason for that one.)

Code
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$valid=1;

if ($uploaded_size > 35000){
   echo "The file is too large.<br />";
   $valid=0;
   }

if (!($uploaded_type =="audio/mpeg3")){
   echo "Only Mp3's are allowed<br />";
   $valid=0;
   }

if ($valid==0){
   Echo "The file was not uploaded";
   }

      else{
         if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){
         echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
      }
      
      else{
         echo "The file was not uploaded";
      }
}





Author

RE: PHP mime types issue

SySTeM
Member

Your avatar

Posts: 1524
Location: England, UK
Joined: 27.07.05
Rank:
HBH Guru
Posted on 27-01-09 22:09
$uploaded_type and $uploaded_size don't even exist on there :s


img138.imageshack.us/img138/6527/sig2ak1.jpg
www.hellboundhackers.org/sig/r/2783.png

http://www.elites0ft.com/
Author

RE: PHP mime types issue


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-01-09 22:31
This is an uploader that I coded from about 3 years:

Code

<?php

$uploaddir = 'upload/';

$uploadfile = $uploaddir.$_FILES['userfile']['name'];

$userfile = $_FILES['userfile']['name'];

$max_upload_size = "5120000";

### Font setup ###
$font = "verdana";
$font_size = "3";
$font_color = "#ff6600";

### Error Messages #######################################################################

# No file to upload
$no_file = "<b><font face=\"$font\" size=\"$font_size\" color=\"$font_color\">Sorry, but you didn't select an image to be uploaded!";

# File is to big
$to_big_file = "<b><font face=\"$font\" size=\"$font_size\" color=\"$font_color\">Sorry, but the image you have select is too big to be uploaded!";

# Not the correct filetype
$not_correct_file = "<b><font face=\"$font\" size=\"$font_size\" color=\"$font_color\">Sorry, but the file you tried to upload is not a valid image!";

# Error to write file to upload directory
$error_write_file = "<b><font face=\"$font\" size=\"$font_size\" color=\"$font_color\">Sorry, but there has been an error processing file! Please try again later!";

# The file is already uploaded!
$already_uploaded = "<b><font face=\"$font\" size=\"$font_size\" color=\"$font_color\">Sorry, the image already Exists on server!";

#########################################################################################

if (!$_FILES['userfile']['name'])
die("$no_file");

if ($_FILES['userfile']['size'] > $max_upload_size)
die("$to_big_file");

if (!in_array($_FILES['userfile']['type'] , array ('audio/mpeg3')))
die("$not_correct_file");

if (file_exists ($uploadfile))
die("$already_uploaded");

if(move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadfile))
header('Location: http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');

else
die("$error_write_file");
 
?>










Edited by on 27-01-09 22:32
Author

RE: PHP mime types issue


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-01-09 23:07
Got it with some research at w3 schools.