Comments (12)
+1 "Must be able to work with multiple files at once"
from codeigniter4.
You're absolutely correct. My last line there implied this, but wasn't very specific:
Most of the image features should be handled through a new Image class.
An issue exists for this one already, actually: https://github.com/lonnieezell/CodeIgniter4/issues/114
Using hooks/events (which is a pub/sub pattern basically) is an interesting idea, and I can see it being potentially very handy. Definitely something to consider more as we get closer to start working on it.
Thanks!
from codeigniter4.
I think the thumbnail creation should be decoupled from the Uploader class. Maybe the uploader should implement some kind of pubsub pattern or should use the events what you mentioned in the ticket about the queue interface.
from codeigniter4.
@lonnieezell I'm trying to make the Uploader Class
https://github.com/davidgv88/CodeIgniter4/blob/upload_class/system/Uploader/Uploader.php
$options = array(
'allowed_types' => array('jpg','png','gif'),
'max_size' => 100
);
$uploader = new \CodeIgniter\Uploader\Uploader(\Config\Services::request(), $options);
$do_upload = $uploader->doUpload('file');
$uploadData = $uploader->uploadData();
from codeigniter4.
Looks like a good start. A couple of comments and/or thoughts:
- You'll need to make sure that Ll comments are in English, please.
- Error strings will need to be localized
- Does it make sense to just return the file objects, instead of keeping a separate record of success and path in $dataUploads?
from codeigniter4.
The more I think about this the more I'm thinking this library isn't needed anymore. The FileCollection class that can be retrieved from the current Request object fulfills all of the standard requirements of being able to upload the files, I believe. Any image-related features would be part of the image library, anyway.
Does this make sense to everyone?
from codeigniter4.
Actually realized, also, that I started to add some file-related validation rules last night, and that pretty much fills out the basics of the uploader class, when combined with the existing UpoadedFile class.
I really think the upload class is unnecessary now, but I'll wait a few days to get other's comments before closing this.
from codeigniter4.
An upload class can provide some convience feature such as file type restriction, auto encrypt filenames, transform filename to lowercase etc. I use these in my own applications. I don't think these belongs to the HTTP "package".
from codeigniter4.
To be fair, though, uploaded files are part of the HTTP request so it makes sense to deal with them there, like any other form input.
Currently, you can grab all of the uploaded files from the request, and they are represented by an UploadedFile class that uses best practice and most secure methods I could find for correctly determining type, etc. It also has a move()
method to move the file from it's temp location to the location of your choice. It also takes care of generating a secure random name if you want.
The Validation library now has elements to validate if a file is an image, restrict to certain mime types or extensions, set a maximum file size or, if an image, maximum dimensions. These all make sense as you are validating an HTTP input, just like you would validate everything else on the form.
So, the only things left from the current Upload class are some of the file naming/move options (like the lowercase option, or removing spaces, or overwriting/appending version numbers to file name. Setting things to lowercase or removing spaces can be done manually when you specify the name, though we could provide options in the File class, though I think that's perhaps stretching it, but would be handy. The overwrite options would make sense to go into the UploadedFile class since the move method is there already.
At that point, I believe all of the current Uploader library functions are taken care of in a way that's actually a little more true to the HTTP process than we have been.
At least, it seems to all make sense to me....
from codeigniter4.
I was thinkg about it with your message in mind, and you're right! The approach is new but the result is the same as used to...
from codeigniter4.
So, the only things left from the current Upload class are some of the file naming/move options (like the lowercase option, or removing spaces, or overwriting/appending version numbers to file name. Setting things to lowercase or removing spaces can be done manually when you specify the name, though we could provide options in the File class, though I think that's perhaps stretching it, but would be handy. The overwrite options would make sense to go into the UploadedFile class since the move method is there already.
File naming rules and whether to allow overwrite (or what to do if naming conflicts arise) sound like either validation or lower-level business rules. While CI traditionally could do all of this stuff in the form_validation library, I don't know whether that's where you actually want it to reside in this case.
After looking up a couple of file move commands/functions/methods, it looks like it's fairly common to pass the source filename (obviously not needed in cases like the UploadedFile
class, where this is already known), the destination path/filename, and, in complex methods, an options field, which usually includes a flag to allow overwrite. PHP's rename()
accepts a context, which can include options like overwrite when it makes sense for the type of stream in use.
from codeigniter4.
Sorry if that was confusing. The naming rules wouldn't be part of validation. They'd be part of the UploadedFile class, which already has a move() method. Sending the overwrite/append a number/etc rules as part of an options array would work great for that, I think, and definitely should be looked into a little more.
from codeigniter4.
Related Issues (20)
- feat: Command `lang:find` behavior with parameters
- Bug: Credit card validation does not work with multiple card HOT 1
- Bug: postgre can not connect to database error HOT 12
- `Model::paginate()` behavior when `$page` exceeds the last page HOT 12
- Bug: CodeIgniter v4.5.1 When I connect Postgres Database I Received Error HOT 4
- Bug: [Error] Call to undefined method Config\Mimes::__set_state() at ROOTPATH/writable/cache/FactoriesCache_config HOT 7
- Bug: [DebugBar] Flush a session flash-data when redirect by "Refresh" method HOT 2
- Add required_if validation rules
- Bug: Entity Standalone Class initialization error HOT 2
- Bug: How can I know which browser name is the request from?
- Bug: How can I know which browser name is the request from? HOT 14
- Bug: storing validation rules in Config/Validation causes error HOT 1
- Bug: Fatal error: Uncaught Error: Undefined constant "ENVIRONMENT" in /var/www/html/MyApp/system/Common.php:777 HOT 1
- Bug: cannot run PHPUnit testing in CI 4.5.1 appstarter HOT 5
- "Deploy API Documentation" fails HOT 1
- Composer PSR-4 notices "does not comply with psr-4 autoloading standard" HOT 16
- Bug: CodeIgniter\Router\RouteCollection::getRoutesOptions(): Argument #1 ($from) must be of type ?string, int given, called in system\Router\DefinedRouteCollector.php on line 49 HOT 3
- Bug: `migrate:rollback -b` impossible due to TypeError HOT 4
- Bug: [Validation] if_exist is not working as intended with arrays HOT 1
- Bug: spark routes doesn't work with `(.+)` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codeigniter4.