1

Before uploading check if file exists then delete this image and upload new image using laravel functionality but showing first uploaded image when hitting image url on browser.

I have face this issue when file name and file type are same.

Below my code

$destinationPath = "public/".$destinationPath;
            $extension = $file->getClientOriginalExtension();
            if($file->isValid() && in_array($extension, $allowedExt)) {
                if (\File::exists($destinationPath.$fileName)) {
                    \File::delete($destinationPath.$fileName);
                }
                if($file->move($destinationPath, $fileName)) {
                    return true;
                }
            } return false;

Also I have cleared all cache and tried on another PC.

Following commands used to clear the cache.

  1. php artisan cache:clear
  2. php artisan config:clear
  3. php artisan route:clear

Please give me Any suggestions to resolve this issue.

9
  • You have a typo: \File::exists($destinationPath..$fileName Two dots Commented Sep 23, 2015 at 11:00
  • Add some debugging in around if (\File::exists($destinationPath..$fileName)) { \File::delete($destinationPath.$fileName); } to see if the file is actually being deleted Commented Sep 23, 2015 at 11:01
  • did you add debugging to see if the file is actually being deleted? what happens if you visit the file url in your browser? Commented Sep 23, 2015 at 11:22
  • is it showing in the public folder on filezilla? Commented Sep 23, 2015 at 11:29
  • why are you deleting it, why not just overwrite the file with the same name? Can you give the url where the image is saved? Commented Sep 23, 2015 at 11:35

1 Answer 1

1

I got that solution. Why not reflecting updated image due to on server side maintain cache this is feature provided by Amazon.

Than i have disabled this feature now its working fine.

I hope my solution really helpful to others who's face such that issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.