npsari Posted October 30, 2011 Share Posted October 30, 2011 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/250077-huge-if-function/ Share on other sites More sharing options...
AyKay47 Posted October 30, 2011 Share Posted October 30, 2011 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.. Quote Link to comment https://forums.phpfreaks.com/topic/250077-huge-if-function/#findComment-1283359 Share on other sites More sharing options...
PFMaBiSmAd Posted October 30, 2011 Share Posted October 30, 2011 The following will give you a 'directory' number (starts at zero) - $x = intval($ID/1000); 0 (0-999) 1 (1000-1999) 2 (2000-2999) ... Quote Link to comment https://forums.phpfreaks.com/topic/250077-huge-if-function/#findComment-1283360 Share on other sites More sharing options...
npsari Posted October 30, 2011 Author Share Posted October 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/250077-huge-if-function/#findComment-1283364 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.