本文整理匯總了PHP中Self::slugify方法的典型用法代碼示例。如果您正苦於以下問題:PHP Self::slugify方法的具體用法?PHP Self::slugify怎麽用?PHP Self::slugify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Self
的用法示例。
在下文中一共展示了Self::slugify方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: uploadImage
public function uploadImage(Request $request)
{
// file was uploaded successfully
if ($request->hasFile('photo') && $request->file('photo')->isValid()) {
// get file object
$file = $request->file('photo');
// separate extension and name
$temp = explode('.', $file->getClientOriginalName());
$ext = array_pop($temp);
$name = implode('.', $temp);
// slugify the name and lowercase the ext
$fileName = Self::slugify($name) . '.' . strtolower($ext);
$destinationPath = public_path('images/uploaded/');
if (file_exists($destinationPath . DIRECTORY_SEPARATOR . $fileName)) {
$fileName = Self::slugify($name) . '-' . Self::generateRandomString(5) . '.' . strtolower($ext);
}
// move to correct folder
$file->move($destinationPath, $fileName);
$i = new File();
$i->title = $request->input('title');
$i->file = $fileName;
$i->save();
}
return redirect('/dashboard/images');
}