I have api based image upload feature. I uploaded the project in a subdomain.
My js(angularjs) :
var data = new FormData();
data.append('picture', $scope.picture);
data.append('title', $scope.title);
data.append('description', $scope.description);
data.append('captured_by', $scope.captured_by);
$http.post('api/SaveGallery',data,{
withCredentials: true,
headers: {'Content-Type': undefined },
transformRequest: angular.identity
}).then(function (data) {
console.log(data)
My Controller:
use Illuminate\Http\Request;
use Session;
use DB;
use Illuminate\Database\Eloquent;
use Illuminate\Support\Facades\Auth;
use Exception;
use Response;
use Image;
use File;
public function SaveGallery(Request $r)
{
if ($r->hasFile('picture')) {
$image = $r->file('picture');
$imageName = $image->getClientOriginalName();
$destinationPath = public_path('images/Gallery');
$img = Image::make($image->getRealPath());
$img->encode('jpg')->save($destinationPath . '/' . $imageName);
DB::table('gallerys')
->insert([
'title' => $r->title,
'picture'=> $imageName,
'description' => $r->description,
'captured_by' => $r->captured_by=='undefined'?'Famous Bag':$r->captured_by,
'create_by' => Auth::user()->username,
'create_date' => date('Y-m-d H:i:s')
]);
return Response::json(['succ' => 'added'], 200); // Status code here
} else {
// $imageName = null;
return Response::json(['picnotfound' => 'picnotfound'], 201); // Status code here
}
}
But when i try to upload picture, it returns 500 server error! I want to store image in images/Gallery path. When i return $destinationPath to test in console, it returns : If i delete this line :$img = Image::make($image->getRealPath());$img->encode('jpg')->save($destinationPath . '/' . $imageName);
, it is ok but image in not stored in the folder. I think Image package problem. I tried base_path instead of public_path as my folder is not in public folder. NOTE:Everything is ok in my local host
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2r7PJHi
via IFTTT
Aucun commentaire:
Enregistrer un commentaire