uploading and using images - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: uploading and using images (/showthread.php?tid=11569) |
uploading and using images - El Forum - 09-20-2008 [eluser]textnotspeech[/eluser] The class has a max height and max width setting. I don't mind helping, but you have to actually read the code that I'm sending or else you won't learn how to do these things for yourself. I'm not mad, but you gotta see it from my perspective it seems like your not even reading the code I posted. If you didn't understand it, that's one thing, but you didn't seem to notice those features. If you find a way that it works with CI's upload class I'd be interested in seeing the code. Don't take this the wrong way, I don't want you to think that I'm angry. uploading and using images - El Forum - 09-20-2008 [eluser]M4rc0[/eluser] No no not at all, it's okay I'm afraid you are getting me wrong too. To me it seems like you are not reading my posts carefully either, or maybe i'm the one not expressing myself clearly. My posts above your replies are always explaining what you are mentioning, as i don't want to be repetitive, i'd rather beeing on second plan here and posting again only when i get a conclusion of my problem. For example, again when i mean validation of max height and max width, it would be adapting your code to use the validation error string that i'm displaying in the form in case of errors Quote:It’d be a lot of trouble to add stuff like valid extensions, max height, max width, max size and set them all with $this->validation->error_string = ‘MSG’; I'm not mad either, i'm actually happy to be using your lib that is great (i really like it). I did read the whole code and i tweaked as well. And when i asked for opinion it's more teorically then pratically, no coding, just what step should i take next since i reached a point that i'll have to re-think what to do (imagination can't get the renamed file name, not imagination's fault but CI's), so i need a different aproach. I apologize if you got me wrong and for the trouble. I will post the changes later. uploading and using images - El Forum - 09-20-2008 [eluser]textnotspeech[/eluser] It's all good. I think I'm just misunderstanding some of your posts. I have other classes that I use for my own error handling and notifying and that is why there's none in the imagination class. It may not be the best way to go but it keeps things portable and prevents redundancy. Just so you know, if the image is larger than the max values, it will resize the image to the max values. I should have taken some time to shape it up for more general use but I figured I'd just post it and let you adapt it. I'm always looking for better ways to do things so if you have any suggestions, let me know. :cheese: uploading and using images - El Forum - 09-22-2008 [eluser]M4rc0[/eluser] Ok so here i am Less talk more code this time, since i have lots to show. I choose Imagination to upload (temp place) and rename and upload (correct place). I'm not using CI upload helper since that would be one extra unnecessary upload. So i had to add a function to rename the picture (random hash) and to display a validation error in case of invalid file type. I'm not caring about max width or max height since imagination takes care of resizing it according to it's ratio (rocks). Size validation can be important but that can wait So i only care about file type now, since i was successfully adding with .zip files (or any other extension). Here's my controller code: Code: function add() Now the imagination changes: I have on the top of the variables a "public $new_name;" Added the function encrypt_name: Code: public function encrypt_name() And on your resize function, there's an if in the beginning, i just added the else code: Code: if($this->valid) So it works! Not perfectly but it works. If i choose a file other then a valid image type, it shows the form again but without the "Invalid file type" error. But at least it doesn't go My trouble is with $CI variable that i see you get with "$CI =& get_instance();" I have never worked with that before, so i tought it would set on my controller (CI instance?) the validation error but it's not setting it. Maybe i have to use the return of the resize function for this. What you think? uploading and using images - El Forum - 09-22-2008 [eluser]M4rc0[/eluser] Yep, just as i tought. I had to change. In the controller: Code: function resize_img($name,$path,$dest=FALSE) The controller now have a private variable called "cover_name" that contains the new cover name. The problem i was having is that i had to return two values: TRUE or FALSE if it worked resizing, and if TRUE the name of the new generated image so i save on database. The only way i found to do this is a private variable called cover_name on the controller (cover is the image). Is there a better way to do this? It feels this variable is not necessary.. So i removed the else on the imagination resize function and now added this on the add function: Code: if($this->validation->run() == FALSE OR $this->resize_img($_FILES['cover']['name'], $_FILES['cover']['tmp_name'],'public/images/covers/') == FALSE) uploading and using images - El Forum - 09-22-2008 [eluser]textnotspeech[/eluser] The $CI->validation is referring to my validation library and not CI's. I've built my own validator that works a little different way than CI's. I am found of doing things my way, and that's why I rewrite a lot of stuff CI does already. This is probably not the best way to go about doing things as I suppose I could just extend CI but that's what I love about CI, it let's you do it your way very easily. If the validation library is already loaded, the Code: $CI =& get_instance(); Code: $CI->load->library('validation'); uploading and using images - El Forum - 09-23-2008 [eluser]M4rc0[/eluser] Quote:"but that’s what I love about CI, it let’s you do it your way very easily" Couldn't agree more. Actually i like you validator too :cheese: I think i'll use in the future. Right now i'm not doing the things how it should be either, i'm not checking for file size so far. I just found a small problem after that renaming function. I'm adding a thumb like this: Code: $image->resize(200,210); The problem is that it's generating a new name for the thumb, and not getting the name from the original image. It's not prepending either (because of the function too). So i have two resized images but with different names. How can i get the name of the image before and just add the _thumb? Without this rename function, how was it working? Was it keeping the original name and prepending the thumb? like original.jpg original_thumb.jpg And the multisize function is generating like 5 different images together. Halp uploading and using images - El Forum - 09-23-2008 [eluser]textnotspeech[/eluser] Once you rename the file, that's it. Before you name it, you can access $this->image_name. maybe you could make an $orig_name private variable out of that in the constructor. That would leave all the functionality but would save the name to persist throughout changes to the image. uploading and using images - El Forum - 09-23-2008 [eluser]M4rc0[/eluser] Good idea, i remembered i added a variable called $new_name, so i used. In the resize function i did this: Code: if($this->new_name){ Now it is getting the name, but it's overwriting it It's not prepending the name "_thumb". Almost there, any idea? You don't have to reply this fast if you are busy man haha This is just for fun i don't want to trouble you uploading and using images - El Forum - 09-23-2008 [eluser]textnotspeech[/eluser] To be honest, I'm kinda lost at this point. I'm sure it's something simple you're overlooking. If you want to send me the modified class, I'd be glad to take a look at it. |