1 Star2 Stars3 Stars4 Stars5 Stars (14 votes, average: 5.00 out of 5)

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.

Tip: Click on images to make them larger. If you find anything wrong on this page or need further assistance please comment below or contact me. 🙂
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 of the fact that 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. 🙂

Subscribe To My YouTube Channel:

 

Warning: unlink(): http does not allow unlinking in PHP was last modified: March 8th, 2019 by Maximus Mccullough

Please like, share and subscribe.

Advanced Programming Made Easy

I hope you enjoyed the article. If I was able to help you please consider a tip for the content.

One Time Tip

more tips

Reoccuring Tips

Tips

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

Pages:Previous 1 2

Leave a Reply

Your email address will not be published. Required fields are marked *

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