私はAPIベースの画像アップロード機能を持っています。サブドメインにプロジェクトをアップロードしました。 写真のアップロードでは、ラーベル5.4で500が返されます。
私の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)
マイコントローラー:
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
}
}
しかし、私は写真をアップロードしようとすると、それは500サーバーエラーを返します!画像/ギャラリーパスに画像を保存したい この行を削除した場合:$ img = Image :: getRealPath()); $ img-> encode( 'jpg') - コンソールでテストする$ destinationPathを返すと、 > save($ destinationPath。 '/'。$ imageName);
でもOKですが、フォルダに保存されていない画像です。イメージパッケージの問題だと思う。 私のフォルダがパブリックフォルダにないので、私はpublic_pathの代わりにbase_pathを試しました。 注:ローカルホストですべてOKです。
私はbase_path()を使用したが、失敗したと述べました。もし私がbase_path()を使って、$ img = Image :: make($ image-> getRealPath()); $ img-> encode( 'jpg') - > save($ destinationPath。 '/'。$ imageName ); write move($ destinationPath、$ imageName);と書いてください。 base_path()を使用し、ルートイメージ/ギャラリーフォルダに保存されたイメージを使用します。しかし、私は、介入という名前のパッケージを使用してイメージのサイズを変更する必要があります。 – Fawel