Help With PHP Code

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

Kfkm09

Established Member
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
<?

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
Close
It worked! Thank you!
 
0
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back