开发者

automatic delete option

I am new to PHP and Javascript.

I am uploading files that after 15 days need to be deleted automatically from the database. Please can anyone help me out.

I am using following code for uploading:

<?php
$nid = 1;
$teaser = false;

// Load node
$node = node_load(array('nid' => $nid));
// Prepare its output
if (node_hook($node, 'view')) {
  node_invoke($node, 'view', $teaser, false);
}
else {
  $node = node_prepare($node, $teaser);
}
// Allow modules to change content before viewing.
node_invoke_nodeapi($node, 'view', $teaser, false);

// Print
print $teaser ? $node->teaser : $node->body;

$target_path = "../mts/sites/default/files/ourfiles/";


//$myfile = basename( $_FILES['uploadedfile']['name']);

$safe_filename = preg_replace( 
                     array("/\s+/", "/[^-\.\w]+/"), 
                     array("_", ""), 
                     trim($_FILES['uploadedfile']['name']));

$target_path = $target_path.$safe_filename;

if(file_exists($target_path))
      {
      echo "<script language=\"javascript\">";
      echo "window.alert ('File already exist')";
      echo "//--></script>";
      }
elseif(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

echo "<script lang开发者_StackOverflowuage=\"javascript\">";
echo "window.alert ('File uploaded succesfully');";
echo "//--></script>";


/*   
echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
*/

} 



$con = mysql_connect("localhost","mts","mts");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Create table
mysql_select_db("mts", $con);
$ut=date("y-m-d @ h:i:s");


mysql_query("INSERT INTO mt_upload (FileName, FilePath,DateTime)
VALUES ('".$safe_filename."', '".$target_path.$safe_filename."',NOW())");


// Execute query
mysql_query($sql,$con);

mysql_close($con);
?>


Since you're using mysql, you'd want to create a PHP script that would connect to your database and delete everything older than 15 days.

*nix: Use a tool like cron to run that script every X hours, where X is a reasonable number for your operation.

Windows: Use a scheduled task to run that script every X hours, where X is a reasonable number for your operation.


Option called Cron job.

Check it in your server.

Set a time duration in the server. Which server checks for time and process the function that you have set.

Automatically the it wont delete the records. You have to initiate an event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜