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

Validation with PHP [closed]
Replacing characters after percent sign with regex
Aptana marks $a = [..] as a syntax error
CI load properties by default
Best way to build multidimensional array (categories ; sub-categories; sub-sub-categories etc.)
creating Woocommerce order with line_item programmatically
Order status error in WooCommerce
Get the current view in a Laravel controller
How to make Freeswitch ESL phpmod?
concrete5 custom block not passing array to view
Is it good or bad for an abstract class to implement an interface? [closed]
Unable to send mails on localhost XAMPP configured with Gmail SMTP
Not Able to start a session on a hosting server
Prepend php divs
Display star rating on loop
JQuery Ajax executing php script with predefined id

Categories

HOME
qt
events
list
jms
selenium-builder
systemd
haproxy
website
adobe
initialization
whmcs
biztalk
iverilog
sympy
gtk
bootstrap-switch
angular4
jodatime
nest-api
android-5.1.1-lollipop
google-sites
checkout
codefluent
opam
libgit2
gollum-wiki
web-config-transform
password-generator
tracing
list-comprehension
network-analysis
region
splunk-query
tightvnc
steam-web-api
xcrun
cucumber-junit
xmlunit
serversocket
markov-chains
char-pointer
des
bluemixtools
unification
telephonymanager
selenide
dagger
fiware-wirecloud
minikube
apache-toree
type-inference
jshint
docker-ucp
react-intl
aws-kinesis-firehose
roracle
head.js
mobile-angular-ui
glimpse
case-when
degrees
cognos-tm1
gawk
bigdecimal
jsf-2.3
nunit-console
django-testing
xcode8-beta4
android-expansion-files
certificate-authority
cortana
variable-length-array
largenumber
nastran
srv-record
mobilefirst-server
shell-extensions
jcheckbox
sunos
lifetime
n-tier-architecture
wicket-1.5
iplimage
inputbox
aho-corasick
miglayout
lync-2010
progress-db
discovery
san
sql-view
libxml-js
statechart
android-authenticator
icenium
handshake
liveconnect
mmc3
litespeed
botnet
libxslt
downgrade
hungarian-notation
android-input-method
oracle-pro-c
eventaggregator
html-components
data-retrieval
.net-client-profile
code-camp

Resources

Encrypt Message