Welcome Guest, Not a member yet? Register   Sign In
  Best strategies when storing images on fileserver
Posted by: El Forum - 10-24-2007, 02:03 PM - Replies (3)

[eluser]E1M2[/eluser]
I'm building a community site that will depend heavily on image uploads. In the beginning my thought was to store everything in one directory with a hash for the filename using SHA2 as MD5 & SHA1 have been known to have potential collisions, I don't even think they are actively used by even the gov't anymore. Anyway, my concern, I don't know when the single directory approach could become more of a hinderance than a benefit as image count piles up.

It's been asked before, 'why don't we just slap the file in a DB blob field'. Now I'm not a DBA and I have thought about that myself considering it would just be a straight shot to the DB without having to access the filesystem thereafter. But, I'm very weary if it turns out that the DB in use has to be changed to another DB down the road and I've heard horror stories of trying to move from one blob type to another. So for me I'm shooting for keeping things on the fileserver.

I've done a search through the forum as well on the interweb, here is the strategy I've decided to run with maybe someone else will find it to be of use, maybe other useful strategies will surface.


Option #1 - Month & Year
IMG_FOLDER/YYYY/MM/ID_FILENAME.EXT

While this looks like a good candidate it doesn't really spread files across the board much and still leaves room for directories to have a massive about of images something I'm trying my best to stay away from.


Option #2 - Hashed
IMG_FOLDER/a-f0-9/a-f0-9/a-f0-9/ID_FULLHASH.EXT

Use the MD5 hash of the image ID. substr() the hash as needed for the 3 sub folder names. For the filename, rename the temp file to the ID plus the full hash to thwart a collision.

Here is an example:

Code:
$id = 10;
$img_hash = md5($id);
$img_node1 = substr($img_hash, 0, 3);
$img_node2 = substr($img_hash, 3, 3);
$img_node3 = substr($img_hash, 6, 3);
        
$img_ref = IMG_DIR . $img_node1 . '/' . $img_node2 . '/' . $img_node3 . '/' .  $id . '_' . $img_hash . IMG_EXT;

// result: IMG_DIR/d3d/944/680/10_d3d9446802a44259755d38e6d163e820.JPG

Conclusion
Def going with a flavor of Option2. Not only does it spread files across directories but best of all, since we used the ID as the base for the hash there is no need to store directory meta data in the DB, we'll always know by md5($id)


  Shouldn't a custom library be logged as when its loaded ?
Posted by: El Forum - 10-24-2007, 12:59 PM - Replies (6)

[eluser]scottelundgren[/eluser]
I've written a custom library and saved it as application/libraries/LDAP.php. The library has a custom config file and it is in application/config/LDAP.php. If I have:

applicaation/config/config.php:

$config['log_threshold'] = 4;

applicaation/config/autoload.php:

$autoload['libraries'] = array('LDAP', 'database', 'session', 'validation', 'email');

when I look at my log file I have this snippet:

DEBUG - 2007-10-24 14:48:53 --> Loader Class Initialized
DEBUG - 2007-10-24 14:48:53 --> Config file loaded: config/LDAP.php
DEBUG - 2007-10-24 14:48:53 --> Helpers loaded: form, url
DEBUG - 2007-10-24 14:48:53 --> Database Driver Class Initialized
DEBUG - 2007-10-24 14:48:53 --> Session Class Initialized
DEBUG - 2007-10-24 14:48:53 --> Encrypt Class Initialized
DEBUG - 2007-10-24 14:48:53 --> Validation Class Initialized
DEBUG - 2007-10-24 14:48:53 --> Email Class Initialized
DEBUG - 2007-10-24 14:48:53 --> Controller Class Initialized

and I'm thinking shouldn't I be able to see my LDAP class loaded in my logs? I'm having some weird behaviour with my library so I'm staring my investigation wondering if the library was even loaded.


  How to add attribute like id in form_dropdown() ?
Posted by: El Forum - 10-24-2007, 12:47 PM - Replies (4)

[eluser]bijon[/eluser]
i want to create a drop_downlist like :

Quote: <select id="country">
<option value="1">Bangladesh</option>
<option value="2">India</option>
<option value="3">UAE</option>
</select>

i know that it can be done by
Quote:echo form_dropdown('country', $options_array, '1');

But it create the code like
Quote: <select name="country">
<option value="1">Bangladesh</option>
<option value="2">India</option>
<option value="3">UAE</option>
</select>

So how can id in the from_dropdown ?
Thanks
Saidur Rahman
Developer
Right Brain Solution Limited


  Preventing resize of smaller images
Posted by: El Forum - 10-24-2007, 12:28 PM - Replies (3)

[eluser]Unknown[/eluser]
Hi, I`m using Image_lib to upload resize images, but now I stopped and don`t know what to do .

I`m using these variables:

Code:
$config['width'] = 800;
$config['height'] = 800;

And the problem is, that if I try to upload an image 200x200 or other size, it will be expanded to 800px. How to allow resizing only to bigger images?

Thanks in advance Smile


  Video tutorial blog help
Posted by: El Forum - 10-24-2007, 07:51 AM - Replies (5)

[eluser]H8train[/eluser]
Hi sory for this noob problem, but im going through the blog tutorial video and am having an error. when i enter the scaffolding to add entries to my table, when i click on "Create New Record" it links to:
/index.php/blog/index.php/blog/scaffolding/add
instead of:
index.php/blog/scaffolding/add

wich gives me a 404 error because its looking in the wrong place.

if I type in the correct URL into the addy bar:
index.php/blog/scaffolding/add
then I get the correct page but when attempt to insert data into the table with this form i get redirected to this url:
/index.php/blog/scaffolding/index.php/blog/scaffolding/insert
but says "No data exists for this table yet." and if From this page I click the "create new entry" link again it just grows the URL to:

/index.php/blog/index.php/blog/index.php/blog/scaffolding/add

Im pretty sure that my base url is messed up in the scaffolding.php but not sure.

please help.

Thanks

Rich


  Upload File type
Posted by: El Forum - 10-24-2007, 05:45 AM - Replies (2)

[eluser]Yash[/eluser]
Hi,

I've set this


$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|flv|avi';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';


in proper location but when I try to load some.flv files..it shows

The filetype you are attempting to upload is not allowed


Is there any more setting...

Thank you


  i cant retrieve the query result
Posted by: El Forum - 10-24-2007, 05:09 AM - Replies (1)

[eluser]mistress_shiira[/eluser]
good eve guys.im doing a simple validation exercise.for this purpose,i have created a databse called dev and a table i named users that contains the fields ID and username.

I have a form that contains a text input for username,password,email and country and a button beside username that checks whether the input does not exist yet in my users table...
Basically,what i would do is make this thing work using codeigniter+xajax.

i have to check whether the username typed already exists or not and then output a message near the username textbox stating whether the username exists or not.
this is how i did this:

Quote:&lt;?php

class Validate extends Controller {
function index() {

$this->load->library('validation');
$this->load->helper(array('form','url'));

//set validation rules
$rules['username'] = 'required|trim';
$rules['password'] = 'required|trim|min_length[6]|max_length[10]';
$rules['email'] = 'required|trim|valid_email';
$rules['country'] = 'required|trim';
$this->validation->set_rules($rules);
//set validation fields
$fields['username'] = 'username';
$fields['password'] = 'password';
$fields['email'] = 'email address';
$fields['country'] = 'country';
$this->validation->set_fields($fields);


function test_function($name) {
$objResponse = new xajaxResponse();
$objResponse->assign("hello","innerHTML",$name);
return $objResponse;
}
function name_check($name){
/*$sql = $this->db->query('select * from users where username=$name');
foreach($query->result() as $row){
$user = $row->username;

$objResponse = new xajaxResponse();
$objResponse->assign("working","innerHTML",$row->ID);
return $objResponse;
}*/
if($name == "hello"){
$objResponse = new xajaxResponse();
sleep(2);
$objResponse->assign("hello","innerHTML",$name);
}else{
$objResponse = new xajaxResponse();
sleep(2);
$objResponse->assign("hello","innerHTML",$name);
}
return $objResponse;
}
$this->load->library('xajax');

$this->xajax->registerFunction("test_function");
$this->xajax->registerFunction("name_check");

$this->xajax->processRequest();

$template['xajax_js'] = $this->xajax->getjavascript('../../');
$this->load->view('failed', $template);
}
}
?&gt;
Another thing,how will you disable the submit button while the information has not been submitted yet or the username has not been checked and not all fields have been filled up?


  multiple theme
Posted by: El Forum - 10-24-2007, 04:25 AM - Replies (1)

[eluser]ningnoht[/eluser]
Hi

If I have multiple theme and then where I should be put theme template folder?





Thank you so much.


  Scope library methods vs helper functions and other related questions
Posted by: El Forum - 10-24-2007, 03:22 AM - Replies (2)

[eluser]xwero[/eluser]
I've been wondering about this for a while. Is it right the scope of library methods and helper functions are the same? Is there a difference performance wise?

According to me the idea is that helpers are library independent, right?

I'm trying to understand the finer details of CI.


  Codeigniter Tutorial
Posted by: El Forum - 10-24-2007, 01:51 AM - Replies (7)

[eluser]PHP Programmer[/eluser]
Hi

is anyone able to view tutorials in http://www.codeigniter.com/tutorials??

It needs to get installed Quick Time Player. I did the same but it still doesn't show anything here.

What should I do?

TIA

Anuj


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
Changing Session cookie -...
by codeus
2 hours ago
hot-reload side effects s...
by PaulC
Today, 02:44 AM
using app/Config/App.php ...
by sam547
Yesterday, 03:04 PM
Setting baseURL in Regist...
by grimpirate
05-15-2025, 02:20 PM
CRUD Code Generator
by DeanE10
05-15-2025, 05:31 AM
CodeIgniter.com - Report ...
by Harry Lyre
05-14-2025, 04:26 AM
Missing closing bracket w...
by abf
05-13-2025, 07:27 PM
Update from 4.6.0 to 4.6....
by FlavioSuar
05-13-2025, 04:17 AM
Sessions old files are de...
by InsiteFX
05-12-2025, 10:30 PM
Ajax post failing with Ty...
by PaulC
05-12-2025, 12:23 AM

Forum Statistics
» Members: 146,570
» Latest member: lilacblosom
» Forum threads: 78,392
» Forum posts: 379,465

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB