php


Codeigniter Image Upload and Watermark for multiple Images


I'm using codeigniter upload and image_lib library to upload and give watermark for multiple images that I'm uploading. Below are the code snippet:
function do_upload_img()
{
if(isset($_FILES['portfolioimg']['size']) != 0){
$name_array = array();
$files = $_FILES;
$cpt = count($_FILES['portfolioimg']['name']);
// $config['source_image'] = ''; //get original image
$config['wm_type'] = 'overlay';
$config['wm_overlay_path'] = './assets/img/watermark.png';
$config['quality'] = 50;
$config['wm_vrt_alignment'] = 'middle';
$config['wm_hor_alignment'] = 'center';
$this->load->library('image_lib', $config);
for($i=0; $i<=$cpt-1; $i++)
{
$_FILES['userfile']['name']= $files['portfolioimg']['name'][$i];
$_FILES['userfile']['type']= $files['portfolioimg']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['portfolioimg']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['portfolioimg']['error'][$i];
$_FILES['userfile']['size']= $files['portfolioimg']['size'][$i];
$imgnam = rand(10,1000000).time();
$ext = pathinfo($files['portfolioimg']['name'][$i], PATHINFO_EXTENSION);
if($this->upload->initialize($this->set_upload_options($imgnam,$ext)))
{
if($this->upload->do_upload())
{
$config['source_image'] = './assets/temp/' . 'Rookie_'.$imgnam.'.'.$ext;
$this->image_lib->initialize($config);
$this->image_lib->watermark();
$name_array[] = $this->upload->data('file_name');
}
}else{
$this->session->set_flashdata('falsemsg','Only jpg, jpeg, png files are allowed to be uploaded.');
}
}
return $name_array;
}else{
return false;
}
}
//Image Upload Initialize
private function set_upload_options($imgnam,$ext)
{
//upload an image options
$config = array();
$config['upload_path'] = './assets/temp/';
$config['allowed_types'] = 'jpeg|jpg|png|JPEG|JPG|PNG';
$config['max_size'] = '0';
$config['overwrite'] = true;
$config['file_name'] = 'Rookie_'.$imgnam.'.'.$ext;
return $config;
}
By using this code I'm changing the actual filename to some random names for each and every image that is uploading.
But now the problem is, sometimes in the $name_array the filenames are coming as the original filename instead of the name that I'm assigning($imgnam = rand(10,1000000).time();).

Related Links

Update HTML table every 5 seconds with mySQL, and PHP?
Bllim DataTables in Laravel 4 throws undefined getQuery() exception
Written html source code in downloaded file from php page
Making a simple search engine php mysql
Make a different IF depending on which page the user came from
PHP Output (function swap) [closed]
spl_autoload_register and properties of the $class variable
PHP Function “opendir()” in Wordpress. Works in one file, but not in other
Check if username or email is taken - PHP
Fastest way to retrieve and display a specific post from another Wordpress site?
Effective way to replace the text with some pattern [closed]
Split string by ;
Change Timezone of Database on the time of connection in ActiveRecord
Running php script via Jenkins Execute shell
Symfony2.0 form date with today
Add 5 minutes difference

Categories

HOME
elasticsearch
jboss
ionic2
plaid
visual-studio-2010
biztalk-2010
openflow
vue-resource
tfs2015
repair
tweepy
jpa-criteria
selection
msmq
cqrs
locationmanager
grocery-crud
multi-step
amazon-elb
asp.net-core-1.0
asciimath
codefluent
psql
data-type-conversion
kaggle
qa
ini
backendless
software-packaging
pubxml
window-managers
npoi
pyspark-sql
instructions
sql-execution-plan
cloudera-manager
xmlunit
autoencoder
formsauthenticationticket
mars-simulator
cheat-engine
reverse-dns
music21
webalizer
tinyioc
ol3-google-maps
hibernate-ogm
spring.net
exc-bad-access
portability
1010
boost-compute
wininet
callouts
gnucash
textblock
currency-exchange-rates
wif4.5
servicestack-bsd
lovefield
360-degrees
wlanapi
ngcordova
nhibernate-criteria
jolie
inequality
windows-rt
visual-c++-2012
ecos
aho-corasick
squeezebox
neo4jphp
pageviews
typesafe-stack
code39
compiler-flags
saga
ggts
microformats
eager-loading
android-authenticator
cgrectmake
uipangesturerecognizer
kolite
memory-pool
reliability
autobench
webclient.uploaddata

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App