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

Conditional Content in Blade Layouts Laravel
funny results with try/catch and sessions
Laravel route filter when *not* starts with?
php sum of amount in array if 2 values exist
php unset array element while keeping numbers in order [duplicate]
PHP out of order execution
How to declare a variable in .php which is then used in an included .php? [duplicate]
Rationale of not using RESTful APIs for Pagination
Difference between simplexml_load_file and simplexml_load_string
How to insert a string with double quotes in the first line of my csv file?
How to insert dropdown list option into database
pdo_informix fails `make test` after `make`
trying to create an algorithm similar to an approximate subset-sum table in PHP
Utf8 Sort Array
Cut an arabic string
How to update using Angular (500 Internal Server Error)

Categories

HOME
google-chrome
powerbi
activemq
code-formatting
theano
website
elisp
google-sheets-query
linker
bittorrent
twitter-oauth
smartgwt
nest-api
gravity
gmp
nullreferenceexception
pfobject
akka-persistence
anova
backtracking
fluent-migrator
substring
unordered-multimap
hevc
code-climate
microprocessors
cucumber-junit
sql-execution-plan
nest
pdfminer
runtimeexception
spinner
cargo
strapi
resampling
icepdf
cloudera-sentry
1wire
optionaldataexception
sendinput
apache-toree
vesta
destroy
absolute
dredd
cordova-ios
karabiner
spring.net
popen
deedle
email-forwarding
emacs25
polymaps
mpmovieplayercontroller
perl-data-structures
cefpython
bigdecimal
nsrunloop
system.net.mail
noclassdeffounderror
uibinder
rails-engines
jeasyui
gwt-syncproxy
univocity
in-app-billing
calcite
cache-manifest
relational-model
kefir.js
ipod
android-audiomanager
htmltidy
n-tier-architecture
iplimage
rpg
accessory
accountmanager
oxygene
django-sites
strcmp
visual-c++-2005
frontbase
boinc
microformats
xs
notin
email-verification
tridion-2011
idispatch
stretch
wndproc
pcspim
prototypal-inheritance
background-repeat
mvcrecaptcha
infopath-2007
jquery-1.4
asp.net-mvc-views
qcar-sdk
aggregator
urchin
tabbarcontroller
main-method
eai
rtti
tso
iphone-sdk-3.1.3
synthesizer
parentid

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App