IT.COM

Help With PHP Code

Spaceship Spaceship
Watch
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

?>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
<?

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.");

}elseif ($_FILES['filename']['size']>1048576){
die('file too big');


} 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

?>

notice the bold text that has been added. this should work (untested) the numbers are the max size it can be in bytes the figure there is 1 MB
 
0
•••
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back