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

Compare dates with PHP [duplicate]
Type casting large integers on a 32 bit server
MySql Pivot table in to Yii CActiveDataProvider
How To Extract Complex Parcel Numbers & Strings Using PHP
Is php://input written to a temp file for large uploads?
Getting err_empty_response when I try to submit a form
Is that possible to remove <a> in a <img> in php or jquery without remove the <a> directly in php?
Only single record getting when i fetch data from another page
Get text value with PHP simple HTML DOM parser
How do I route all subdomains to index.php using htaccess without 301 redirect
Mysql error while trying to make a login php [duplicate]
do comments slow PHP down?
How to properly set “0000-00-00 00:00:00” as a DateTime in PHP
update value in config.php with another php script
Laravel Refreshing JWT tokens
Codeigniter - How to upload original image with thumbnail image?

Categories

HOME
jboss
android-espresso
blast
mousemove
filesize
bing-search
docker-cloud
cryptography
liferay-7
fogbugz
openflow
gtk
solution
documentum
business-intelligence
angular4
powermock
bundler
pygobject
asciimath
office-ui-fabric
boomi
salt-cloud
activeadmin
maven-surefire-plugin
pdf.js
hevc
offline-caching
tortoisehg
code-climate
ninject
boolean-logic
amazon-iam
tightvnc
mongoengine
des
stackpanel
aurelia-cli
praat
imgur
klee
classnotfoundexception
angular-datatables
section508
rm
sony-future-lab-n
ilrepack
karabiner
android-sharing
webvtt
sesame
business-rules
ltrace
allegro
deviare
e
nsrunloop
tsqlt
gcloud-node
mathml
declarative
groovyfx
gnucash
okta-api
wikimedia-commons
gdl
miniconda
android-mapview
html.actionlink
cfwheels
ipod
ocmockito
jquery-mobile-flipswitch
osascript
aho-corasick
box2dweb
jini
hyperloglog
pageviews
jchartfx
map
spring-social-linkedin
typesafe-stack
saga
xsd2code
node.js-stream
statechart
days
simplecov
playorm
trialware
wcf-callbacks
motodev-studio
server-variables
tablet-pc
qcar-sdk
printqueue
3270
fxruby
accumulator
regioninfo

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile