Jump to content

Block Extentions, not Types in Uploading!


JustinMs66@hotmail.com

Recommended Posts

here is my upload code:
[code]<html><form method='post' action='' enctype='multipart/form-data'>
    <input name="MAX_FILE_SIZE" value="999999999999" type="hidden">
      Choose a file to upload
      <input name="uploadedfile" type="file">
      <input name="submit" type="submit" value="Upload">

<?php
// notice bad file TYPES (but i want Extentions)
$bad_types = array('application/x-php');
//if they ARE bad, display error
if( in_array( $_FILES['uploadedfile']['type'], $bad_types ) )
{
    echo "That File type is not supported.";
}
else
{
//otherwise, upload!
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['uploadedfile']['name']).
        " has been uploaded. here is the link to your file: <a href='uploads/".  basename( $_FILES['uploadedfile']['name']). "'>".  basename( $_FILES['uploadedfile']['name'])."</a><br>";
    } else{
        echo "Error!";
    }
}
?>
</body> </html>[/code]
and i want it to block EXTENTIONS (.php), NOT file types (application/x-php)
please help?
Link to comment
https://forums.phpfreaks.com/topic/27800-block-extentions-not-types-in-uploading/
Share on other sites

Try this:
[code]if(eregi('.php$', $_FILES['uploadedfile']['name'])) {
    echo "That File type is not supported.";
}[/code]

If you have more bad extensions you can write like this:
[code]if(eregi('.php$|.php3$|.htm$|.html$', $_FILES['uploadedfile']['name'])) {
    echo "That File type is not supported.";
}[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.