Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Delete a file from a folder using PHP

Featured Replies

<?php
$dir = 'images/';
$filename = 'image1.jpg';
unset($dir.$filename);
?>

 

This would delete a picture located in images/image1.jpg

  • Author
<?php
$dir = 'images/';
$filename = 'image1.jpg';
unset($dir.$filename);
?>

 

This would delete a picture located in images/image1.jpg

 

Where would I put this?

 

Because I have an upload form, and the user uploads the pics to an folder on the server then they go into a gallery to display the pictures so where would I put that peace of code ?

When you upload a file via PHP, it is saved in a temp folder.

You have the ability to process this file, and to copy it to a desired location if needed (which I guess would be your gallery directory e.g. images/gallery).

 

Where the code would go would depend on when you actually wanted to delete a picture. During the part of your code where you want to delete a picture, you can insert the code and change the filename/directory as needed.

 

If you're using a functions file then you could implement the above code as a simple function which you could call at any point in your script where you need to delete a file.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.