Jump to content

Huge IF function :(


npsari

Recommended Posts

Hello! I have a small question...

I used to upload all my member's images in same directory, but now i've decided to put 1000 images in each directory

 

<?php

$ID = $get_member_id_from_mySQL;

if($ID >=0 AND $ID <=1000 ){
$directory_name='from0to1000';
} else if($ID >=1001 AND $ID <=2000 ){
$directory_name='from1001to2000';
} else if($ID >=2001 AND $ID <=3000 ){
$directory_name='from2001to3000';
} else if($ID >=3001 AND $ID <=4000 ){
$directory_name='from3001to4000';
}

if(is_dir($directory_name)){
imagejpeg( $tmp_img, "{$directory_name}{$image_name}" );
}else{
mkdir("/path/to/my/$directory_name", 7777);
imagejpeg( $tmp_img, "{$directory_name}{$image_name}" );
}


?>

 

Is there any simpler way to continue with the IF function? Because I can't do this until 1000000 ?

Link to comment
https://forums.phpfreaks.com/topic/250077-huge-if-function/
Share on other sites

you will want to use a loop for this, probably a while loop.

Do not set your directory permissions to 777, this will lead to insecurities.. the highest you should ever need to go is 755, which will give only the owner write permission, and everyone else read/execute permissions..

Link to comment
https://forums.phpfreaks.com/topic/250077-huge-if-function/#findComment-1283359
Share on other sites

Oops, thanks for telling me about file permissions, I will change it tommorow for sure. I am on my mobile now, cant check the code you given me Mabis, will work on it tommorow. Cheers for replies. If someone has a different way to do it, please share.

Link to comment
https://forums.phpfreaks.com/topic/250077-huge-if-function/#findComment-1283364
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.