- Impact
- 1
In this piece of an image hosting script, how could I limit the size of the file being uploaded? I know almost nothing about PHP, so you would really need to give me the whole line of code and tell me where to put it, lol! Thanks!
<?
define ('IMAGES_PATH',"images/"); // make sure that your scripts have write privileges to this path!!!
$filename = $_FILES['filename']['name'];
$tmp_filename = $_FILES['filename']['tmp_name'];
if ($tmp_filename) {
// test to make sure the file is of the correct file type
$filename_array = explode(".",$filename);
$type= $filename_array[1];
if ($type!="gif") {
die ("Image not recognized as a .gif.");
} else {
$newfile = IMAGES_PATH."rand.gif"; // setup destination filename
if (true) {
@$result = move_uploaded_file($tmp_filename,$newfile); // @ used to suppress error messages
// move_uploaded_file also has a security feature built in to only move files that are HTTP posted uploads.
if (!$result) {
die ("Unable to move file.");
} else {
echo "Congratulations! Your file has been uploaded to Zonoid.com!";
} // end if - !$result
} else {
die( "Please rename your image. '$newfile' already exists.");
} // end if - file_exists
} // end if - $type
} else {
die("No file provided.");
} // end if - $tmp_filename
?>
<?
define ('IMAGES_PATH',"images/"); // make sure that your scripts have write privileges to this path!!!
$filename = $_FILES['filename']['name'];
$tmp_filename = $_FILES['filename']['tmp_name'];
if ($tmp_filename) {
// test to make sure the file is of the correct file type
$filename_array = explode(".",$filename);
$type= $filename_array[1];
if ($type!="gif") {
die ("Image not recognized as a .gif.");
} else {
$newfile = IMAGES_PATH."rand.gif"; // setup destination filename
if (true) {
@$result = move_uploaded_file($tmp_filename,$newfile); // @ used to suppress error messages
// move_uploaded_file also has a security feature built in to only move files that are HTTP posted uploads.
if (!$result) {
die ("Unable to move file.");
} else {
echo "Congratulations! Your file has been uploaded to Zonoid.com!";
} // end if - !$result
} else {
die( "Please rename your image. '$newfile' already exists.");
} // end if - file_exists
} // end if - $type
} else {
die("No file provided.");
} // end if - $tmp_filename
?>