php


Image upload and resize function not working as it must


I have simple resize image function in my laravel project. It should upload original image and make thumbnail of it.
After form submitting I got two images but the original image is placed in wrong directory. This is the function in my controller
if (Input::hasFile('image') && !Input::get('remove_image')) {
$file = Input::file('image');
$filename = str_random(20);
$image = new ImageResize($file);
$original = $filename . '.'. $file->getClientOriginalExtension();
$thumb = $filename . '-thumb.' . $file->getClientOriginalExtension();
$file->move(public_path() . '/uploads', $original);
$imagePath = '/uploads/' . $original;
$thumbPath = '/uploads/' . $thumb;
$image->crop(200, 200);
$image->save('uploads/' . $thumb);
}
Basically when I upload image.jpg I get two images image.jpg and image-thumb.jpg. Both images should be save in uploads i.e. public/uploads/ BUT only thumbnail is saved there.
The original image is saved in **bootstrap**/uploads/. Why is going in bootstrap... directory? I didn't mentioned it anywhere?
Leave only the directory to where you want to save the original. Try to change this line which is moving the image
$file->move(public_path() . '/uploads', $original);
with this one ( remove the public path )
$file->move('uploads', $original);
You can try to replace the public_path() method to url('/'). Not sure this will help but I don't have good experiences with public_path()
Image::make($request->file('image'))->resize(462, 462)->save('upload_path/filename.jpg'));
Try This Code..
Use Image Intervention to resize and save the image
Image::make($avatar)->resize(250, 250)->save(public_folder('/uploads/'.$filename));
The resize function will resize the image and save function will save the image to uploads folder. Give a desired filename to $filename variable.

Related Links

Output date in YYYY-MM-DDThh:mmTZD format in php
MySQL INSERT IGNORE Adding 1 to Non-Indexed column
PHP - How to rename the uploaded file? [duplicate]
Using YML file in Laravel
Mysql Statement to pull info from database in particular order with subsets
PHP cookies and session
Add reCaptcha code to php script (CakePhp)
Insert form data into MySQL database table
how to find out missing date in mysql using php
PHP curl_exec() not working online but works fine on localhost as CURLOPT_POSTFIELDS not attaching data to http post request
Unable to call method using facade in laravel 5.1
Wordpress prepared LIKE query [closed]
Opencart redirect defined routes
Php header error cannot modify header information [duplicate]
How to make foreign key same int type ?
Laravel 5.1: Auth::login() not persisting

Categories

HOME
openshift
openxml
key
operating-system
plpgsql
embedded-resource
odata
tfs2015
ipv6
onvif
kurento
mailing-list
clickable-image
lda
migrate
rangy
cuba-platform
fosuserbundle
pickle
tfsbuild
amazon-mws
node-webkit
pst
candlestick-chart
perfino
pyopencl
function-points
managed-c++
webviewclient
multi-dimensional-scaling
msdeploy
android-service
dnsmasq
windowsiot
mongodb-3.4
osx-lion
sql-execution-plan
directfb
jfxtras
textmate2
pdfnet
xll
assemblies
reset
pyttsx
haar-classifier
webalizer
django-static-precompiler
gestures
visual-format-language
winmerge
kendo-editor
pecl
allegro
controllers
deviare
java-2d
xcode6.4
system.web.optimization
persistent-object-store
openmrs
jsr363
wikimedia-commons
diawi
ui4j
textpattern
stack-smash
netdatacontractserializer
unhandled
embeddedwebserver
gflags
pass-by-value
nhibernate-criteria
multivariate-testing
squeezebox
stripe.net
eclim
colon
iirf
xs
rikulo
arel
office-app
simplecov
playorm
border-box
kobold2d
liveconnect
mmc3
datacontracts
botnet
webresponse
anonymous-types
bass
pinax
icicles
j2mepolish
asdoc
projectpier

Resources

Encrypt Message