Comments (8)
Update:
I ran a foreach after the $this->upload->get_multi_upload_data();
and before return $image_data;
and specified the images sizes in there and seems to be working well:
foreach($image_data as $k => $v) { $config = array( 'source_image' => $v['full_path'], 'maintain_ratio' => TRUE, 'width' => 1400, 'height' => 800 ); $this->load->library('image_lib', $config); $this->image_lib->resize(); }
Hope this helps anyone else...
from codeigniter-multi-upload.
This is doesn't quite work... (Darn!)
It does for a single upload, but upload more than one image seems to break it.
Any ideas would be much appreciated...
from codeigniter-multi-upload.
Is there an actual error? Here's a snippet of what I use in one of my models for reference. This loads the image_lib library once outside the loop and the settings are being cleared after each resize.
if($this->upload->do_multi_upload("files")){
$data = $this->upload->get_multi_upload_data();
$this->load->library("image_lib");
foreach($data as $file){
if((int)$file["is_image"] === 1){
$this->image_lib->initialize(array(
"width" => 1280,
"height" => 1024,
"master_dim" => "width",
"source_image" => $file["full_path"]
));
$this->image_lib->resize();
$this->image_lib->clear();
}
}
}
from codeigniter-multi-upload.
Hi Steven,
Not getting an error as such, but when I tried multiple images, whilst they still uploaded the first didn't resize and the subsequent image was resized to top-left, with the rest of the image as a black background.
But thanks very much or your snippet, this looks much better, I'll give that a whirl...
from codeigniter-multi-upload.
Your code works a treat, thanks again.
I reckon not having $this->image_lib->clear();
was partly to blame.
Cheers!
from codeigniter-multi-upload.
Any thoughts on why it's uploading both original and resized?
Ideally just need to resize...
from codeigniter-multi-upload.
Here's my full model code:
function do_multi_upload($property_id) { $this->load->library('upload'); // Filenames array $filenames_ar = array(); $i = 0; foreach($_FILES['files']['name'] as $k => $v) { $rand = mt_rand(100000,999999); $segments = explode('.', $v); $extension = strtolower(array_pop($segments)); $name = "img_{$property_id}_{$rand}.{$extension}"; $filenames_ar[$k] = "{$name}"; $i++; } $this->upload->initialize(array( "upload_path" => FCPATH.'static/images/uploaded/', "file_name" => $filenames_ar, "allowed_types" => 'jpg', "max_size" => '0', )); // stvnthomas if(!$this->upload->do_multi_upload("files")) { $error = array('error' => $this->upload->display_errors()); return $error; } else { if($this->upload->do_multi_upload('files')){ $image_data = $this->upload->get_multi_upload_data(); $this->load->library('image_lib'); foreach($image_data as $file){ if((int)$file["is_image"] === 1) { $this->image_lib->initialize(array( 'source_image' => $file['full_path'], 'maintain_ratio' => TRUE, 'width' => 1400, 'height' => 800, 'master_dim' => 'auto' )); $this->image_lib->resize(); $this->image_lib->clear(); } } } return $image_data; } }
from codeigniter-multi-upload.
Sorry for the late reply. I don't initially see anything wrong with your snippet. Hopefully you got it sorted out. This post seems to imply calling clear() before initialize() might fix the problem: https://ellislab.com/forums/viewthread/173145/#865917.
from codeigniter-multi-upload.
Related Issues (20)
- Codeigniter 2.2.0 HOT 6
- Problem changing filenames HOT 2
- get_multi_upload_data() returns an empty array? HOT 2
- How to get All uploaded file names HOT 2
- Display files that failed to upload HOT 1
- files dats array
- Advanced feature + script
- Upload Runtime Notice HOT 6
- Oh, that's a piece of sh*t HOT 1
- 500 internal server error when uploading lots of files HOT 1
- Unable to locate the specified class: Session.php
- Sanitize Filename & Encrypt Name issue Codeigniter 3 HOT 4
- Declaration of MY_Upload should be compatible with CI_Upload HOT 1
- Declaration of MY_Upload should be compatible with CI_Upload HOT 8
- Call to undefined method MY_Upload::clean_file_name() HOT 1
- Can't Display get_multi_upload_data HOT 2
- Update library for run in CodeIgniter 3.x HOT 1
- Insert to database HOT 2
- Not working when i select attachments one by one
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 codeigniter-multi-upload.