您好我如何在照片中包含网址功能
function photoUpload($file)
{
$messages = '';
$t = [];
$i = 0;
try {
$input = array(
'files' => $file,
'type' => Input::get('type'),
'max' => 1,
);
$files = array($input['files']);
$image = \Image::make($file->getRealPath());
$bigpath = public_path() . '/pictures/contentPhoto/big/';
$mediumpath = public_path() . '/pictures/contentPhoto/medium/';
$thumbpath = public_path() . '/pictures/contentPhoto/thumb/';
$maxFile = $input['max'];
$image->backup();
$rules = array('file' => 'max:50000|mimes:png,gif,jpeg,jpg');
if( !is_array($files) )
return ['status'=>false, 'msg'=> 'Bir problem var!' ];
if(count($files)>$maxFile)
return ['status'=>false, 'msg'=> 'En az bir fotoğraf gerekli!' ];
$status = array();
foreach ($files as $file) {
$isim = md5(uniqid('', true));
$t[]['org_name'] = $file->getClientOriginalName();
$t[$i]['extension'] = $file->getClientOriginalExtension();
$t[$i]['remote_name'] = $isim . '.' . $t[$i]['extension'];
$t[$i]['path'] = $thumbpath;
$t[$i]['remote_name'] = $isim . '.' . $file->getClientOriginalExtension();
$validator = Validator::make(array('file' => $file), $rules, [], ['file' => $file->getClientOriginalName()]);
if ($validator->passes()) {
$t[$i]['info'] = '<li>' . $file->getClientOriginalName() . ' bu fotoğraf yüklendi.' . '</li>';
$t[$i]['result'] = true;
$t[$i]['remote_full_name'] = Config::get('app.url') . '' . Config::get('app.pictures_db') . '/contentPhoto/thumb/' . $t[$i]['remote_name'];
$status[] = 1;
if (!file_exists(public_path().'/pictures/contentPhoto/')) {
mkdir(public_path().'/pictures/contentPhoto/', 0777, true);
}
$post_photo=$_FILES['files']['name'];
$post_photo_tmp=$_FILES['files']['tmp_name'];
$ext = pathinfo($post_photo, PATHINFO_EXTENSION); // getting image extension
list($width_min,$height_min)=getimagesize($post_photo_tmp); // fetching original image width and height
$ratio = $width_min / $height_min;
// Big Size
$newwidth_min=700; // set compressing image width
$newheight_min=($height_min / $width_min) * $newwidth_min; // equation for compressed image height
$big = $image->resize($newwidth_min,$newheight_min);
$big->sharpen(18)->save($bigpath.$t[$i]['remote_name'],60);
$big->reset();
if($ratio < 1) {
$t[$i]['ratio'] = false;
// Medium Size
$newwidth_min=320; // set compressing image width
$newheight_min=($height_min / $width_min) * $newwidth_min; // equation for compressed image height
$medium = $image->resize($newwidth_min,$newheight_min);
$medium->sharpen(8)->save($mediumpath.$t[$i]['remote_name'],60);
$medium->reset();
// Thumb Size
$newwidth_min=220; // set compressing image width
$newheight_min=($height_min / $width_min) * $newwidth_min; // equation for compressed image height
$thumb = $image->resize($newwidth_min,$newheight_min);
$thumb->sharpen(8)->save($thumbpath.$t[$i]['remote_name'],60);
$thumb->reset();
} else {
$t[$i]['ratio'] = true;
// Medium Size
$targetHeight= 320;
$targetWidth = 240;
$imgWidth = $image->getWidth();
$imgHeight = $image->getHeight();
$verticalRatio = $targetHeight / $imgWidth;
$horizontalRatio = $targetWidth / $imgHeight;
$imgAvg = min($verticalRatio,$horizontalRatio);
$newHeight = $imgHeight * $imgAvg;
$newWidth = $imgWidth * $imgAvg;
$medium = $image->resize($newWidth,$newHeight);
$medium->fit(320,170)->sharpen(8)->save($mediumpath.$t[$i]['remote_name'],60);
$medium->reset();
// Thumb Size
$targetHeight= 320;
$targetWidth = 240;
$imgWidth = $image->getWidth();
$imgHeight = $image->getHeight();
$verticalRatio = $targetHeight / $imgWidth;
$horizontalRatio = $targetWidth / $imgHeight;
$imgAvg = min($verticalRatio,$horizontalRatio);
$newHeight = $imgHeight * $imgAvg;
$newWidth = $imgWidth * $imgAvg;
$thumb = $image->resize($newWidth,$newHeight);
$thumb->fit(320,170)->sharpen(8)->save($thumbpath.$t[$i]['remote_name'],60);
$thumb->reset();
}
$insertDb = DBDosya::insertPicture($file->getClientOriginalName(), $isim.'.'.$file->getClientOriginalExtension(), '' . Config::get('app.pictures') . '/', '.'.$file->getClientOriginalExtension() );
$t[$i]['id'] = $insertDb;
} else {
$t[$i]['result'] = false;
$mesajlar = $validator->messages();
$htmlMesaj = '';
foreach ($mesajlar->all('<li>:message</li>') as $mesaj) {
$htmlMesaj .= $mesaj;
}
$t[$i]['info'] = $htmlMesaj;
}
$messages .= $t[$i]['info'];
$i++;
}
$status = in_array(1, $status);
} catch (Exception $e) {
return ['status' => false, 'msg' => $messages . '<li>' . $e->getMessage() . '</li>',];
}
return ['status' => $status, 'msg' => $messages, 'data' => $t[0]];
}
它可以在此文件附带的文件中正常运行。 但是当我用url获取照片时,我得到了getRealPath()错误。 如何使用此功能处理URL中的照片