Jump to content

[SOLVED] PHP Unlink


steviez

Recommended Posts

Hi,

 

I am trying to have some files deleted from my server when a user closes their account, the only thing is it wont work!

 

Here is my code so far:

 

<?php
include("../connect");
include("../header");

mysql_connect("$DBSERVER", "$USERNAME", "$PASSWORD");
mysql_select_db("$DATABASENAME","$db");

$filepath = "/home/steviez/YC9R5F01/htdocs/music4play/audio/";
$file = "SELECT FROM audio WHERE user_id = '68'";

if (! unlink ($file,$filepath)) {
   echo ("Couldn't delete file");
} else {
    echo ("Removed $file");
}
?>

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/40429-solved-php-unlink/
Share on other sites

<?php
include("../connect");
include("../header");

mysql_connect("$DBSERVER", "$USERNAME", "$PASSWORD");
mysql_select_db("$DATABASENAME","$db");

// query the database for the file name first... how ever you want to do that... once you have that done continue below

$file = "/home/steviez/YC9R5F01/htdocs/music4play/audio/" . $row['filename'];


if (! unlink ($file)) {
   echo ("Couldn't delete file");
} else {
    echo ("Removed $file");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/40429-solved-php-unlink/#findComment-195672
Share on other sites

I tryed the code above but i cant get it working, here is my code now:

 

<?php
include("../connect");
include("../header");

$sql = "SELECT * FROM audio WHERE user_id = '68'";
$result = mysql_query($sql) or die(mysql_error());
$filename = "$result";
$path = '/home/steviez/YC9R5F01/htdocs/xxx/audio/'.$filename;
if (!unlink($filename))
  {
  echo ("Error deleting $filename");
  }
else
  {
  echo ("Deleted $filename");
  }
?>

Link to comment
https://forums.phpfreaks.com/topic/40429-solved-php-unlink/#findComment-195722
Share on other sites

try

 

<?php
include("../connect");
include("../header");

$sql = "SELECT * FROM audio WHERE user_id = '68'";
$result = mysql_query($sql) or die(mysql_error());
$row_result = mysql_fetch_assoc($result);

$path = '/home/steviez/YC9R5F01/htdocs/xxx/audio/'.$row_result['fieldoffilename']; // update the field name...

if (!unlink($path))
  {
  echo ("Error deleting $path");
  }
else
  {
  echo ("Deleted $path");
  }
?>

Link to comment
https://forums.phpfreaks.com/topic/40429-solved-php-unlink/#findComment-195738
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.