SUKOHI / Surpass

A PHP package mainly developed for Laravel to manage uploading images using Ajax and displaying thumbnail.
29 stars 8 forks source link

After replace the old image still exists in the folder #9

Open dsfser opened 8 years ago

dsfser commented 8 years ago

To fix this:

add:

if($this->isOverwrite()){
    $oldid = Input::get(self::KEY_OVERWRITE_ID);
    $olddb = DB::table(self::TABLE)->where('id', $oldid);
    $image_file = $olddb->select('dir', 'filename')->first();
    $remove_path = $this->filePath($image_file->dir, $image_file->filename);
    File::delete($remove_path);
}

to: (in src/Surpass.php)

public function save($attributes = []) {

after:

if(!file_exists($save_path)) {

            throw new Exception('The directory doesn\'t exist.');

        } else if(!is_writable($save_path)) {

            throw new Exception('The directory is not writable.');

        }

Thats all!

SUKOHI commented 8 years ago

Hi, dsfser! Thank you for kind of you. :)))

I've just added your code into this package. And I also added your name in README.md as a token of my gratitude. (If you don't like it, please inform me of it. I'll remove. Thank you!)