Jump to content


Photo

How to use the unlink function?


  • Please log in to reply
3 replies to this topic

#1 Jurik

Jurik
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 10 October 2006 - 08:21 AM

Hi people i'm trying to work-out how to use the unlink() function in PHP, I have a file in a folder called videos can the file is called ICT_Video how do I go about using the unlink function to delete this file when the delete link is pressed?

#2 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 10 October 2006 - 08:39 AM

Are you running under windows or unix derivative.

If you are running under unix you'll need to have permissions set on the file before you can delete it (unlink is an alias of delete).
SA PHP Archives - www.phparchives.za.org

#3 thedarkwinter

thedarkwinter
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts
  • LocationLondon

Posted 10 October 2006 - 08:41 AM

Hi

as long as you have permission to delete the file you can just call

<?php
$filename = "/tmp/ictmovie.txt";
unlink($filename);

From a web-page the user is something like "apache" or "www-data" so its not "root" therefore you may not have permission to delete the file if its owned by root. If you are running an MS server, im not suer how the persmissions work but you need to check in IIS or Apache (whatever your web-server is).

Cheers,
tdw
Remember - if you don't figure it out yourself, you'll probably forget it tomorrow :)

#4 Jurik

Jurik
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 10 October 2006 - 10:46 AM

Im using windows and EasyPHP, its going to run off a local server its not going to be on the internet.

Will I need to set permissions then? Alsonin regards to the $filename = "/tmp/ictmovie.txt"; peice of code. I have the ictmovie.mov stored in a MYSQL database and when the user clicks deletes I want it to find the name of the file from the database, go to the fodler and delete it, is this possible with unlink?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users