All pastes #259561 Raw Edit

Something

public text v1 · immutable
#259561 ·published 2006-11-27 15:46 UTC
rendered paste body
<?php
$upload_dir = "images/"; 
$size_bytes = 1048576; 
$limit_file_type = "no";
$allowed_file_type = array('image/gif',
                          'image/pjpeg',
                          'image/jpeg',
                          'image/png',
                          'image/jpg');

         if (!is_dir("$upload_dir")) {
     die ("The directory <b>($upload_dir)</b> doesn't exist");
         }
       if (!is_writeable("$upload_dir")){
            die ("The directory <b>($upload_dir)</b> is NOT writable, Please Chmod (777)");
         }


if (is_uploaded_file($_FILES['filetoupload']['tmp_name']))
{

        
        $size = $_FILES['filetoupload']['size'];
        
        if ($size > $size_bytes)
        {
            echo "File Too Large. File must be <b>$size_bytes</b> bytes.";
            exit();
        }
            
        if (($limit_file_type == "yes") && (!in_array($_FILES['filetoupload']['type'],$allowed_file_type)))
        {
            echo"wrong file type";
            exit();
        }

        
        $filename =  $_FILES['filetoupload']['name'];
        
        if(file_exists($upload_dir.$filename)){
            echo "Oops! The file named <b>$filename </b>already exists";
            exit();
        }

       if (move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$filename)) {

           echo "File (<a href=$upload_dir$filename>$filename</a>) uploaded!";
           exit();

        }
        else
        {
            echo "There was a problem moving your file";
            exit();
        }
}

?>