Warning: unlink(): http does not allow unlinking in PHP

Another Way To Get An Accurate Path in PHP

You can also use the function dirname(__FILE__); This will do the exact same thing as getcwd(). You can store it in a variable as well to get the path. Most of the time when programmers want to get a path to a directory they are working in they will use this function.

 $abpath =dirname(__FILE__);
 echo $abpath;

Example of using Unlink() in PHP

So now, let’s say that I have image uploads in a folder called “upload” outside the admin directory. I want to give users the ability to delete their images and files using unlink. They are working in an admin directory to delete a file in a different directory called uploads. Here is an example of the code.

if(isset($_POST['submit'])){
$file=$_POST['file'];
$abspath=$_SERVER['DOCUMENT_ROOT'];
$dir = $abspath.'/includes/upload/';
unlink($dir."".$file);
 }

I could not use the other two methods because I am deleting files outside the admin directory. So I used $_SERVER[‘DOCUMENT_ROOT’] and concatenated manually the path to the folders “/includes/upload/”.

If you were deleting images in the admin directory, you could use the other two methods. 🙂 If you need more help, I created a post here with codes that show you how to delete files in a directory with PHP unlink.

Only cool people share!

 

Warning: unlink(): http does not allow unlinking in PHP was last modified: January 28th, 2023 by Maximus Mccullough
Summary
Warning: unlink(): http does not allow unlinking in PHP
Article Name
Warning: unlink(): http does not allow unlinking in PHP
Description
In order to delete an image or file off of your server in PHP you have to use unlink(). This function will delete the file from your server. This is a permanent action and can not be undone once the process is completed.
Author
Publisher
A1WEBSITEPRO LLC
Logo
Warning: unlink(): http does not allow unlinking in PHP

Pages:Previous 1 2

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.