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

How to write correct syntax for myname [closed]
getting error when try to save shipping information for user using magento 2 api
foreach with a simple variable?
SQL sub query from PHP PDO query
inserting record if count of column is less than two else not inserting into mysql
MethodNotAllowedHttpException in RouteCollection.php line 218 what can I do?
dompdf showing quesetion marks Instead of arabic characters
Wordpress Multisite - Nginx with php-fpm random 404 errors
I can't compare password from my database and the one inputted
Filling the foreign key field in one form from another form of related models in yii2
Laravel 5 and Cashier on Company table
PHP list files in directory between time X and Y
Fatal error: Can't use method return value in write context in codeigniter
Scheduled entity in onFlush is different instance
php, explode is not working, php preg_replace is not working
How to save expire sesion when I close browser

Categories

HOME
user-interface
subdomain
initialization
autocomplete
stored-procedures
gprs
native-base
angular2-template
fireloop
lapack
phpstorm-2017.1
fullcalendar-scheduler
google-cloud-logging
varnish-vcl
spam
gitkraken
sharedpreferences
candlestick-chart
ratio
cube
audit
matlab-app-designer
netbios
python-2.x
caesar-cipher
custom-keyboard
telephonymanager
llvm-ir
plane
jqgrid-asp.net
permission-denied
viewmodel
cyanogenmod
winston
nslayoutconstraint
alertify
nsrunloop
zynq
jenkins-workflow
qtcpsocket
deferred-rendering
adp
timestamping
exists
utf-16
django-redis
persistent-object-store
wikimedia-commons
perceptron
http.client
screen-orientation
android-studio-import
auto-generate
darwin
shoes
signed
r.java-file
htmltidy
mojo
image-rotation
aho-corasick
communicate
android-2.3-gingerbread
sql-function
air-native-extension
flipboard
hyphen
infinite
jquery-lazyload
aero
cmath
simplecov
story
border-box
getopt-long
pcspim
java.lang.class
uipangesturerecognizer
type-safety
wiktionary
motodev-studio
play2-mini
rtd
jmenu
getimagesize
mysqli-multi-query
processors
activex-exe
synthesizer

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