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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.