0
私はプログラミングに慣れていないため、以下の問題について助けが必要です。イメージアップロードスクリプト - サイズ変更の方法
以下のスクリプトを使用して、画像のアップロードを制御しています。
1024x768
に画像のオートライザーを追加する簡単な方法はありますか?
public function index()
{
$validator = Validator::make(Input::all(), [
'image' => 'required|image|max:' . (1024 * 3),
]);
if ($validator->fails()) {
$messages = $validator->messages();
echo json_encode([
'return' => 'error',
'message' => $messages->first('image')
]);
} else {
$originalName = Input::file('image')->getClientOriginalName();
$extension = Input::file('image')->getClientOriginalExtension();
$size = Input::file('image')->getSize();
$type = (Auth::check()) ? Auth::user()->default_image_privacy : 'public';
$adult = Input::has('adult') ? Input::get('adult') : 0;
$adult = ($adult != 1) ? 0 : 1;
$status = (Settings::get('auto_approve_images') == 1) ? 'active' : 'pending';
$image = new Image;
$image->user_id = (Auth::check()) ? Auth::user()->id : 0;
$image->file_name = $originalName;
$image->file_extn = $extension;
$image->file_size = $size;
$image->status = $status;
$image->type = $type;
$image->adult = $adult;
$image->ip = Net::getIP();
$image->save();
$imageFolder = floor($image->id/1000) + 1;
$imageFolder = md5($imageFolder);
$imageFolder = substr($imageFolder, 1, 10);
$imageFolder = trim($imageFolder);
$image->folder = $imageFolder;
$image->save();
$destinationPath = public_path('uploads/' . $imageFolder);
$fileName = $image->id . '.' . $extension;
Input::file('image')->move($destinationPath, $fileName);
$destinationPathThumb = public_path('thumb/' . $imageFolder);
if (! File::isDirectory($destinationPathThumb)) {
File::makeDirectory($destinationPathThumb, 0755, true);
}
$fileNameThumb = $image->id . '.' . $extension;
$thumbWidth = (int) Settings::get('thumb_width');
$thumbWidth = ($thumbWidth < 80) ? 100 : $thumbWidth;
$thumbHeight = (int) Settings::get('thumb_height');
$thumbHeight = ($thumbHeight < 80) ? 100 : $thumbHeight;
Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameThumb, $thumbWidth, $thumbHeight);
$fileNameMed = $image->id . '_md.' . $extension;
$medWidth = 700;
$medHeight = 600;
Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameMed, $medWidth, $medHeight);
echo json_encode([
'return' => 'success',
'imageUid' => $image->id
]);
}
exit();
}
public function link()
{
$validator = Validator::make(Input::all(), [
'url' => 'required|url',
]);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator);
} else {
$originalName = basename(Input::get('url'));
$nameSplit = explode('.', $originalName);
$extension = $nameSplit[count($nameSplit) - 1];
if (! in_array($extension, ['jpeg', 'jpg', 'png', 'bmp', 'gif'])) {
return Redirect::back()->withErrors($validator);
}
$type = (Auth::check()) ? Auth::user()->default_image_privacy : 'public';
$adult = Input::has('adult') ? Input::get('adult') : 0;
$adult = ($adult != 1) ? 0 : 1;
$image = new Image;
$image->user_id = (Auth::check()) ? Auth::user()->id : 0;
$image->file_name = $originalName;
$image->file_extn = $extension;
$image->status = 'active';
$image->type = $type;
$image->adult = $adult;
$image->ip = Net::getIP();
$image->save();
$imageFolder = floor($image->id/1000) + 1;
$imageFolder = md5($imageFolder);
$imageFolder = substr($imageFolder, 1, 10);
$imageFolder = trim($imageFolder);
$image->folder = $imageFolder;
$image->save();
$destinationPath = public_path('uploads/' . $imageFolder);
$fileName = $image->id . '.' . $extension;
File::copy(Input::get('url'), $destinationPath . '/' . $fileName);
$size = File::size($destinationPath . '/' . $fileName);
$image->file_size = $size;
$image->save();
$destinationPathThumb = public_path('thumb/' . $imageFolder);
if (! File::isDirectory($destinationPathThumb)) {
File::makeDirectory($destinationPathThumb, 0755, true);
}
$fileNameThumb = $image->id . '.' . $extension;
$thumbWidth = (int) Settings::get('thumb_width');
$thumbWidth = ($thumbWidth < 80) ? 100 : $thumbWidth;
$thumbHeight = (int) Settings::get('thumb_height');
$thumbHeight = ($thumbHeight < 80) ? 100 : $thumbHeight;
Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameThumb, $thumbWidth, $thumbHeight);
$fileNameMed = $image->id . '_md.' . $extension;
$medWidth = 700;
$medHeight = 600;
Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameMed, $medWidth, $medHeight);
return Redirect::to('/upload/success?id=' . $image->id);
}
}
public function success()
{
if (! Input::has('id')) {
return Redirect::to('/');
}
$imageIdArr = explode(',', Input::get('id'));
$imageIdArr = array_where($imageIdArr, function($key, $value)
{
return is_numeric($value);
});
$imageIdArr = array_unique($imageIdArr);
if (empty($imageIdArr)) {
return Redirect::to('/');
}
$imagesInfo = Image::whereIn('id', $imageIdArr)->get();
return View::make('upload.success', [
'imagesInfo' => $imagesInfo,
]);
}
は答えをあなたにクリスありがとうございます。上記のソースコードのどこにあなたが示唆している行を入力するかは、多くの人に尋ねることでしょう。 – arcadios