本文整理汇总了PHP中File::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP File::delete方法的具体用法?PHP File::delete怎么用?PHP File::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File::delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete
/**
* Delete a file (remove it from the disk)
*
* @param string $fileName The full path to the file
*
* @return boolean True on success
*/
public function delete($fileName)
{
$ret = $this->fileAdapter->delete($fileName);
if (!$ret && is_object($this->abstractionAdapter)) {
return $this->abstractionAdapter->delete($fileName);
}
return $ret;
}
示例2: deleteFile
/**
* Delete downloadable file from path and DB
*
* @param $id
* @return mixed
*/
public function deleteFile($id)
{
$file = Download::find($id);
File::delete($file->filename);
$file->delete();
return redirect()->back()->with('flash_message', $file->filename . ' deleted');
}
示例3: boot
public static function boot()
{
parent::boot();
static::deleting(function ($medium) {
\File::delete($medium->path);
});
}
示例4: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$familia = Familia::findOrFail($id);
$validator = Familia::validator(Input::all());
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
$datos = Input::all();
if (Input::file('foto')) {
$file = Input::file('foto');
$destinationPath = 'uploads/images/';
$filename = Str::random(20) . '.' . $file->getClientOriginalExtension();
$mimeType = $file->getMimeType();
$extension = $file->getClientOriginalExtension();
$upload_success = $file->move($destinationPath, $filename);
if ($familia->foto != 'fam.jpg') {
File::delete($destinationPath . $familia->foto);
}
$datos['foto'] = $filename;
} else {
unset($datos['foto']);
}
$familia->update($datos);
Session::flash('message', 'Actualizado Correctamente');
Session::flash('class', 'success');
return Redirect::to('/dashboard/familia');
}
示例5: saveAsThumbnail
public function saveAsThumbnail($folderPath, $fileName_withExtension, $targetHeight, $targetWidth)
{
/* load up the image */
$image = Yii::app()->image->load($this->filePath);
/* determine the original image property landscape or protrait */
$imageWidth = $image->width;
$imageHeight = $image->height;
$isImageLandscape = $imageWidth > $imageHeight;
$isImageProtrait = $imageHeight > $imageWidth;
$isImageSquare = $imageHeight == $imageWidth;
/* determine the target image property */
$isTargetImageLandscape = $targetWidth > $targetHeight;
$isTargetImageProtrait = $targetHeight > $targetWidth;
$isTargetImageSquare = $targetHeight == $targetWidth;
$finalImagePath = $folderPath . '/' . $fileName_withExtension;
if (file_exists($finalImagePath)) {
$file = new File($finalImagePath);
$file->delete();
}
$image->resize($targetWidth, $targetHeight, Image::WIDTH);
$resizeFactor = $targetWidth / $imageWidth;
$resizedImageHeight = ceil($imageHeight * $resizeFactor);
if ($resizedImageHeight < $targetHeight) {
$image->crop($targetHeight, $targetWidth);
$image->resize($targetWidth, $targetHeight, Image::HEIGHT);
} else {
if ($resizedImageHeight > $targetHeight) {
$image->crop($targetHeight, $targetWidth);
}
}
$image->save($finalImagePath);
return $finalImagePath;
//$image->resize(400, 100)->rotate(-45)->quality(75)->sharpen(20);
//$image->save(); // or $image->save('images/small.jpg');
}
示例6: postDelete
/**
* Remove the specified company from storage.
*
* @param $company
* @return Response
*/
public function postDelete($model)
{
// Declare the rules for the form validation
$rules = array('id' => 'required|integer');
// Validate the inputs
$validator = Validator::make(Input::All(), $rules);
// Check if the form validates with success
if ($validator->passes()) {
$id = $model->id;
$model->delete();
$file_path = public_path() . '/uploads/' . $model->filename;
$file_ok = true;
if (File::exists($file_path)) {
$file_ok = false;
File::delete($file_path);
if (!File::exists($file_path)) {
$file_ok = true;
}
}
// Was the blog post deleted?
$Model = $this->modelName;
$model = $Model::find($id);
if (empty($model) && $file_ok) {
// Redirect to the blog posts management page
return Response::json(['success' => 'success', 'reload' => true]);
}
}
// There was a problem deleting the blog post
return Response::json(['error' => 'error', 'reload' => false]);
}
示例7: update
public function update(Request $request, $id)
{
$this->validate($request, ['name' => 'required', 'lastname' => 'required', 'password' => 'required|min:6', 'email' => 'required|email']);
$user = User::find($id)->first();
if ($request->file('edit-user-photo')) {
$this->validate($request, ['edit-user-photo' => 'required|image|mimes:jpeg,jpg,png,bmp,gif,svg']);
$userFile = $user->avatar_path . $user->avatar;
if (\File::isFile($userFile)) {
\File::delete($userFile);
}
$file = $request->file('edit-user-photo');
$avatar_path = $this->_user_photo_path;
$avatar = $file->getClientOriginalName();
$file->move($avatar_path, $avatar);
$user->avatar = $avatar;
$user->avatar_path = $avatar_path;
}
$user->name = $request->get('name');
$user->lastname = $request->get('lastname');
$user->email = $request->get('email');
$user->password = bcrypt($request->get('password'));
$user->save();
flash()->success('', 'Redaguotas!');
return redirect()->back();
}
示例8: update
public function update($id)
{
if (Auth::id() != $id) {
return Redirect::to('http://google.com');
}
$user = Auth::User();
$validator = Validator::make(Input::all(false), ['email' => 'required|email|unique:users,email,' . $id, 'password' => 'min:5|confirmed:password_confirmation', 'first_name' => 'required', 'last_name' => 'required']);
if ($validator->passes()) {
$img_ava = $user->avatar_img;
$password = Input::get('password');
if (Input::hasFile('avatar_img')) {
if (File::exists(Config::get('user.upload_user_ava_directory') . $img_ava)) {
File::delete(Config::get('user.upload_user_ava_directory') . $img_ava);
}
if (!is_dir(Config::get('user.upload_user_ava_directory'))) {
File::makeDirectory(Config::get('user.upload_user_ava_directory'), 0755, true);
}
$img = Image::make(Input::file('avatar_img'));
$img_ava = md5(Input::get('username')) . '.' . Input::file('avatar_img')->getClientOriginalExtension();
if ($img->width() < $img->height()) {
$img->resize(100, null, function ($constraint) {
$constraint->aspectRatio();
})->crop(100, 100)->save(Config::get('user.upload_user_ava_directory') . $img_ava, 90);
} else {
$img->resize(null, 100, function ($constraint) {
$constraint->aspectRatio();
})->crop(100, 100)->save(Config::get('user.upload_user_ava_directory') . $img_ava, 90);
}
}
$user->update(['username' => null, 'email' => Input::get('email'), 'password' => !empty($password) ? Hash::make($password) : $user->password, 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name')]);
return Redirect::back()->with('success_msg', Lang::get('messages.successupdate'));
} else {
return Redirect::back()->withErrors($validator)->withInput();
}
}
示例9: setImageAttribute
/**
* Upload the image while creating/updating records
* @param File Object $file
*/
public function setImageAttribute($file)
{
// Only if a file is selected
if ($file) {
File::exists(public_path() . '/uploads/') || File::makeDirectory(public_path() . '/uploads/');
File::exists(public_path() . '/' . $this->images_path) || File::makeDirectory(public_path() . '/' . $this->images_path);
File::exists(public_path() . '/' . $this->thumbs_path) || File::makeDirectory(public_path() . '/' . $this->thumbs_path);
$file_name = $file->getClientOriginalName();
$file_ext = File::extension($file_name);
$only_fname = str_replace('.' . $file_ext, '', $file_name);
$file_name = $only_fname . '_' . str_random(8) . '.' . $file_ext;
$image = Image::make($file->getRealPath());
if (isset($this->attributes['folder'])) {
// $this->attributes['folder'] = Str::slug($this->attributes['folder'], '_');
$this->images_path = $this->attributes['folder'] . '/';
$this->thumbs_path = $this->images_path . '/thumbs/';
File::exists(public_path() . '/' . $this->images_path) || File::makeDirectory(public_path() . '/' . $this->images_path);
File::exists(public_path() . '/' . $this->thumbs_path) || File::makeDirectory(public_path() . '/' . $this->thumbs_path);
}
if (isset($this->attributes['image'])) {
// Delete old image
$old_image = $this->getImageAttribute();
File::exists($old_image) && File::delete($old_image);
}
if (isset($this->attributes['thumbnail'])) {
// Delete old thumbnail
$old_thumb = $this->getThumbnailAttribute();
File::exists($old_thumb) && File::delete($old_thumb);
}
$image->save(public_path($this->images_path . $file_name))->fit(150, 150)->save(public_path($this->thumbs_path . $file_name));
$this->attributes['image'] = "{$this->attributes['folder']}/{$file_name}";
$this->attributes['thumbnail'] = "{$this->attributes['folder']}/thumbs/{$file_name}";
unset($this->attributes['folder']);
}
}
示例10: boot
public static function boot()
{
parent::boot();
News::deleting(function ($newsItem) {
File::delete($newsItem->image);
});
}
示例11: agregar
public function agregar()
{
$userid = Auth::user()->id;
$curso = new Curso();
$curso->nombre = Input::get('nombre');
$curso->descripcion = Input::get('descripcion');
//$file = Input::file('image');
$curso->activo = Input::get('activo');
$curso->tipo = Input::get('tipo');
$curso->basefile = "";
$curso->id_user = 1;
$curso->save();
$the_id = $curso->id;
$curso = Curso::find($the_id);
$file = Input::file('logo');
$destinationPath = 'temp/';
$filename = $userid . "" . $file->getClientOriginalName();
Input::file('logo')->move($destinationPath, $filename);
$file = ParseFile::createFromFile($destinationPath . "/" . $filename, $filename);
$file->save();
$url = $file->getURL();
$curso->img = "" . $url;
$jobApplication = new ParseObject("cursos");
$jobApplication->set("myid", $the_id);
$jobApplication->set("img", $file);
$jobApplication->save();
$curso->save();
File::delete($destinationPath . "/" . $filename);
}
示例12: updateInactiveModules
/**
* Update the inactive modules
* @param mixed
* @return mixed
*/
public function updateInactiveModules($varValue)
{
$arrModules = deserialize($varValue);
if (!is_array($arrModules)) {
$arrModules = array();
}
foreach (scan(TL_ROOT . '/system/modules') as $strModule) {
if (strncmp($strModule, '.', 1) === 0) {
continue;
}
// Add the .skip file to disable the module
if (in_array($strModule, $arrModules)) {
if (!file_exists(TL_ROOT . '/system/modules/' . $strModule . '/.skip')) {
$objFile = new File('system/modules/' . $strModule . '/.skip');
$objFile->write('As long as this file exists, the module will be ignored.');
$objFile->close();
}
} else {
if (file_exists(TL_ROOT . '/system/modules/' . $strModule . '/.skip')) {
$objFile = new File('system/modules/' . $strModule . '/.skip');
$objFile->delete();
}
}
}
return $varValue;
}
示例13: destroy
public function destroy($id)
{
$image = Image::find($id);
$image->delete();
File::delete($image->image);
return Redirect::back()->withInput()->withErrors('Image #' . $id . ' was deleted.');
}
示例14: cropCoverPhoto
public function cropCoverPhoto($Croppath, $upload_id)
{
$uploader = new Utils_Uploader(array('jpeg', 'jpg', 'png'));
$uploads = self::find($upload_id);
$oldpath = $uploads->path;
$oldname = $uploads->name;
$uploadTypeModel = Model_Upload_Type::find($uploads->type_id);
$typeName = $uploadTypeModel->types;
if (file_exists($oldpath . $oldname)) {
File::delete($oldpath . $oldname);
}
$img = $Croppath;
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = $oldpath . "crop_image_" . $upload_id . ".png";
$original = $oldpath . $oldname;
//$thumbnail = $path . 'min_' . $newFile;
$success = file_put_contents($file, $data);
//Image::load($file)->preset('coverimage')->save($thumbnail); //360 width
Image::load($file)->preset($typeName)->save($original);
//1260 width
File::delete($file);
return $oldname;
}
示例15: boot
public static function boot()
{
parent::boot();
Event::deleting(function ($event) {
File::delete($event->image);
});
}