Jump to content

cbox


Recommended Posts

Posted

upload.php

<?php
  // Configuration
     $allowed_filetypes = array('.rar','.zip','.sppf','.ppf','.serenity','.txt', '.png','.jpg', '.bmp'); 
     $max_filesize = 1310720; 
     $upload_path = './files/'; 
  
  $filename = $_FILES['userfile']['name']; 
  $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
  
  if(!in_array($ext,$allowed_filetypes))
     die('The file you attempted to upload is not allowed.');
  
  if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
     die('The file you attempted to upload is too large, our limit is 10MB.');

  if(!is_writable($upload_path))
     die('You cannot upload to the specified directory, please CHMOD it to 777.');

  // Upload the file to your specified path.
  if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
        echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; 
     else
        echo 'There was an error during the file upload.  Please try again.'; // It failed .

?>

 

Page with upload (Like index.html)

<form action="./upload.php" method="post" enctype="multipart/form-data">

<label for="file"></label>
<div align="center"><input name="userfile" id="file" type="file" /> <br />

<button>Upload File</button>

 

 

The most basic there is.

Posted (edited)
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);

 

Simple question, but without actually testing this code, I beleive this will return anything from the first instance of a period to the end of the filename.

 

 

Edit: Confirmed, yes it will. Simple fix, use strrpos instead of strpos.

Edited by Dark Slipstream
Posted
iBotFiles is my tiny upload area. I'm not going to mess with its source, it works the way it is and thats fine with me. My php.ini is maxed at 5MB of which my hoster limits, it just loops if larger because of a php timeout.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...