PHP - Delete Cache Files
How can I delete cache files when any update take place.
I don't need to delete files after certain period of time pass. Similar TutorialsI have built a small database which use the Twitter API to extract data from the listed members XML files (http://twitter.com/users/show.xml?screen_name=username) and it works well, but since the database makes several calls everytime a page loads I get kicked out very quickly, even with a small memberbase. So I wonder what solution would help with this problem? I have considered dropping the XML data into the database and saving each XML file on the server, but I am not sure what solution would be best? Hi, I need YOUR help with a piece of code. My body normally helps me, but he's on vacation. I have a folder (/var/www/html/upload/files/) where files are uploaded to. There can be files at the root of (/uploads/) and there can be files in subfolders of (/uploads/)... eg: (/uploads/subfolder1/files_here), (/uploads/subfolder2/files_here) I want to modify my script (below) that only delete old files at the root (/uploads/), to also delete files (but NOT subfolders) older than 10 days. Do not delete subfolders, regardless of date. You can modify the existing code to make it more efficient, if you have time/patience. I'm grateful for your help. This is the code I have for the root folder (not recursive): $dir = '/var/www/html/upload/files/'; echo "STARTING\n"; if (is_dir($dir)) { if ($dh = opendir($dir)) { while ($file = readdir($dh)) { if(!is_dir($dir.$file)) { if (filemtime($dir.$file) < strtotime('-10 days')) { //if 10 days old, delete echo "Deleting $dir.$file (old)\n"; unlink($dir.$file); } } } } else { echo "ERROR. Could not open directory: $dir\n"; } } else { echo "ERROR. Specified path is not a directory: $dir\n"; } closedir($dh); echo "DONE\n"; I have a delete statement to delete images, but I also want it to delete the thumbnail image as well. $query = "DELETE from products where urnid = '$urnid'"; if(file_exists("images/$product.jpg")){ unlink("images/$product.jpg")} Is there a way to delete the product_th.jpg image? I have a php script that I wrote that enters information into a database and uploads images to the server. What I need to do now is delete the files from the server when the corresponding database records are deleted. How would I go about doing that? Hi guys, Im a newb here, so bear with me! Still learning the ropes. I want to delete all files from my server that are 6 hours old since being uploaded to the site. I believe i need a cron job? I currently have this script in its framework... Code: [Select] <?php //time interval for deletion to occur... $x = 30; //timestamp $current_time = time(); //the file you wish to delete $file_name = 'file.txt'; //timestamp $file_creation_time = filemtime($filename); //extract difference $difference = $current_time - $file_creation_time; //if difference = $x...then delete file if ($difference == $x) { unlink($file_name); } Would that work automatically or would it need a cron to run it? And how could i test it, that bit worries me. Many thanks. Maybe some of the great coders here can help this noob out. So here is what I have so far: Code: [Select] //set age criteria for deletion $age = 60; //get current date $datenow = date("Y-m-d"); //set the range we want to delete $delete_range = $datenow - $age; //get old user_id from users table $oldusers_users = mysql_query ("SELECT user_id FROM users WHERE lastvisit < $delete_range "); //get user_id from images table that correspond to users table $oldusers_images = mysql_query ("SELECT user_id FROM images WHERE $oldusers_users=user_id.images "); //find folders that correspond to the usernames and delete $oldusers_files = mysql_query ("SELECT username FROM users WHERE lastvisit < $delete_range "); //print out username //$result = mysql_($oldusers_files); $foldername = mysql_result($oldusers_files, 0); $sigspath = "sigs/"; unlink($sigspath . $foldername . ".gif/index.php"); rmdir($sigspath . $foldername . ".gif"); //now delete user_id's from database mysql_query("DELETE * FROM users WHERE user_id=$oldusers_users"); mysql_query("DELETE * FROM images WHERE user_id=$oldusers_images"); unset($oldusers_users, $oldusers_images, $oldusers_files, $foldername, $sigspath ); mysql_close($link); Right now it is only returning the first entry, not the entire list that meets the criteria. It does delete that one file though but does not remover the rows from the database. I am sure the database stuff is jacked up I am really new to that part. What am I doing wrong here or is there a better way to do this perhaps i have made an delete files script which works for only one directory but not sub directory so i want to delete files of same extention from directory and subdirectory. My current code is Code: [Select] <? $dir = 'hmm/'; function scanr($dir){ $arr = glob($dir.'/*.jpg'); foreach($arr as $vv){ //check if $vv is a file if(is_file($vv)){ //if file, get the filename $vx=explode('/',$vv); $file=$vx[count($vx)-1]; // if no extension delete the file unlink($vv); // print the deletion message echo $vv." deleted!<br>";}else{ // if $vv is a dir then scan it again for files scanr($vv); }} } scanr($dir); ?> Hi all. Here is my scripts which allow user to check multiple rows of data and delete it , but it require select data and click for twice to delete the rows , what should be the error? Code: [Select] <form name="frmSearch" method="post" action="insert-add.php"> <table width="600" border="1"> <tr> <th width="50"> <div align="center">#</div></th> <th width="91"> <div align="center">ID </div></th> <th width="198"> <div align="center">First Name </div></th> <th width="198"> <div align="center">Last Name </div></th> <th width="250"> <div align="center">Mobile Company </div></th> <th width="100"> <div align="center">Cell </div></th> <th width="100"> <div align="center">Workphone </div></th> <th width="100"> <div align="center">Group </div></th> </tr> </form> <? echo "<form name='form1' method='post' action=''>"; while($objResult = mysql_fetch_array($objQuery)) { echo "<tr>"; echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>"; echo "<td>$objResult[addedrec_ID] </td>"; echo "<td>$objResult[FirstName]</td>"; echo "<td>$objResult[LastName] </td>"; echo "<td>$objResult[MobileCompany] </td>"; echo "<td>$objResult[Cell] </td>"; echo "<td>$objResult[WorkPhone] </td>"; echo "<td>$objResult[Custgroup] </td>"; echo "</tr>"; } echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">"; if (isset($_POST['delete']) && isset($_POST['checkbox'])) // from button name="delete" { $checkbox = ($_POST['checkbox']); //from name="checkbox[]" $countCheck = count($_POST['checkbox']); for($d=0;$d<$countCheck;$d++) { $del_id = $checkbox[$d]; $sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id"; $result2=mysql_query($sql) or trigger_error(mysql_error());;; } if($result2) { $fgmembersite->GetSelfScript(); } else { echo "Error: ".mysql_error(); } } echo "</form>"; Thanks for every reply. <body> <?php include 'sql.php'; $query = "SELECT * FROM validation"; $result = mysqli_query($con , $query); $rows = mysqli_fetch_assoc($result) ; $totals = mysqli_num_rows($result) ; ?> <div id="css"> <form > <table width="80%" border="0" cellpadding="2" cellspacing="2" > <caption><h2>Personal Details of Customers</h2></caption> <tr class="white"> <td bgcolor="#330033"> </td> <td bgcolor="#330033"> Id Number </td> <td bgcolor="#330033"> Full Name </td> <td bgcolor="#330033"> Email Address </td> <td bgcolor="#330033"> Website </td> <td bgcolor="#330033"> Comment </td> <td bgcolor="#330033"> Time </td> </tr> <?php while($rows=mysqli_fetch_assoc($result) { <tr> <input type="raido" name="ID" value="<?php echo $rows['ID']; ?>" /> <td bgcolor="#FFFFCC"><?php echo $rows['ID'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Name'];?> </td> <td bgcolor="#FFFFCC"><?php echo $rows['Email'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Website'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Comment'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Time'];?></td> <td> </td> <td> <a href="delete.php? ID= "$rows[ID]" /"> <input type="submit" name="del" value="Delete" /> </a> <input type="button" name= "edit" value="Edit" /> </td> </tr> }?> </table> </form> </div> </body> Hi,
I wish to find out is there any possible that I can delete some data inside my php website but inside my sql database, the record will still at there?
Thank you.
I'm trying to set it so that it will delete an entire populated directory based upon a value in the database then after finishing that to go back and delete that row in the database. my current code is Code: [Select] <?php $page_title = "Central Valley LLC | Photo Addition" ?> <?php include("header.php"); ?> <?php include("nav.html"); ?> <div id="content"> <form action="delprod.php" method="post" enctype="multipart/form-data"> <label for="which">Choose A Product To Remove:</label> <?php $con = mysql_connect("localhost","phoenixi_cv","centraladmin"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("phoenixi_cvproducts", $con); $result = mysql_query("SELECT * FROM Products"); echo "<select name=\"which\">"; while($row = mysql_fetch_array($result)) { echo "<option "; echo "value=\"" . $row['id'] . "\">"; echo $row['Name'] . "</option>"; } echo "</select>"; mysql_close($con); ?> <br /> <input type="submit" name="submit" value="Submit" /> </form> </div><!--#content--> <?php include("footer.html") ?> and the delete script Code: [Select] <?php $con = mysql_connect("localhost","phoenixi_cv","centraladmin"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("phoenixi_cvproducts", $con); $result = mysql_query("SELECT id FROM Products WHERE id=$_POST['which']"); $row = mysql_fetch_array($result) chdir('assets'); chdir('images'); $mydir = $row . '/'; $d = dir($mydir); while($entry = $d->read()) { if($entry!="." && $entry!="..") { unlink($_POST['which'] . '/' . $entry); } } rmdir($mydir); $result = mysql_query("DELETE * FROM Producs WHERE id=$_POST['which']"); ?> Thank you in advance for all your help. any easier ways of approaching this will be welcome as well I need to know when a file was last modified to see if the browser has an updated cached version, if the browser does use its cache otherwise get the most current version. How can I do this? I have some JavaScript that sends an AJAX request to the following PHP script every 4 seconds. The idea behind this is that every 4 seconds a new, randomly generate piece of content is loaded. This works fine in Firefox and Chrome, however when I test it in IE it seems to just load the same piece of content over and over again. I'm pretty sure there is nothing wrong with the script so could this be something to do with IE caching the first piece of content returned? Thanks for any help. $random_number = 0; $random_number = rand(1,6); if ($random_number == 1 ) { echo("<a href=\"\"><h4>Aliquam erat volutpat. Vivamus feugiat tempor quam, faucibus elementum.</h4><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae ante at erat tempor facilisis. Quisque blandit faucibus suscipit. Proin suscipit est sed. </p></a>"); } if ($random_number == 2) { echo("<a href=\"\"><h4>Quisque ac lacus nibh, ac semper ante. Sed imperdiet.</h4><p>Vestibulum aliquam pellentesque lacus quis mollis. Proin quis lobortis libero. Ut nec tempor lectus. Pellentesque habitant morbi tristique senectus et netus id. </p></a>"); } if ($random_number == 3) { echo("<a href=\"\"><h4>Suspendisse vestibulum dui augue, nec viverra erat. Proin id.</h4><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eu sollicitudin elit. Cras mauris mi, luctus non luctus quis, tristique vitae turpis turpis duis. </p></a>"); } if ($random_number == "4") { echo("<a href=\"\"><h4>Vestibulum gravida elit posuere arcu.</h4><p>Phasellus sit amet rutrum purus. Cras vulputate pretium quam eleifend viverra. Morbi convallis eros ac tellus suscipit nec euismod nibh semper. In quam posuere. </p></a>"); } if ($random_number == "5") { echo("<a href=\"\"><h4>Vestibulum ante ipsum primis in.</h4><p>Aliquam consectetur aliquet libero. Mauris malesuada tortor eu ipsum mollis sit amet blandit erat sollicitudin. Cras consequat dui ac elit semper pharetra amet. </p></a>"); } if ($random_number == "6") { echo("<a href=\"\"><h4>Nam ornare, nisl non interdum aliquam, erat urna consequat elit, vel.</h4><p>Nulla ut libero est, eu convallis urna. Nullam fringilla mollis ligula, id fringilla enim sagittis non. Nunc lectus nunc, condimentum eget imperdiet massa nunc.</p></a>"); } Hi, I have a question. is that code below made a problem in google search, mean if I put this codes in header did google find my homepage? header( 'Cache-Control: no-store, no-cache, must-revalidate' ); header( 'Cache-Control: post-check=0, pre-check=0', false ); header( 'Pragma: no-cache' ); header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); Thnx. T I want to set the correct header / cache values for a site. I am working on a social network / forum style site. I want to ensure that every page a user requests results in a fresh one being requested from the server as most content changes by the minute. (1) How would I set this? (2) Also, can I prevent nav bars being reloaded as these never, ever change. I run an image hosting site and it's using a lot of resources. I temporaly disabled the images by using this code: <?php $myImage = imagecreatefromjpeg('ua.jpg'); header("Content-type: image/jpeg"); imagejpeg($myImage); imagedestroy($myImage); ?> I redirected all images to one, but he server still getting high loads. Is there a way to cache this image so it doesn't use many resources? I've tried to disable caching of HTML for certain pages but they seem to prevent the storing of the php sid cookies. Is there any way to prevent caching and keep cookie? I did some research on the topic and came across no-cache='set cookie' but the description of that directive seems opposite my need. Help is a greatly appreciated! Hi Guys
I have recently been looking into implementing browser caching after reading this: https://developers.g...ctices/cachingĀ
There are a few things in that google article that don't make much sense to me so I'm hoping someone can clarify.
Firstly Question
The document says:
" we recommend that you configure your web server to explicitly set caching headers and apply them to all cacheable static resources"
This implies you can set caching headers for just some resources. How would you do this? Lets assume I only wanted to set caching headers for a file styles.css - would I need to output headers within the CSS file and then change the extension to .php? e.g.
<link rel="stylesheet" href="styles.php"/>Second question Etags have me very confused. How would you set etag headers for specific files and then generally? And if you set the etag in the header of the main php page does that mean everything gets cached? Any help someone can provide would be very, very welcome! Drongo Does anyone know how to cache Tweets as to not reach the API rate limit? I am using the Twitter-provided widget to display multiple profiles on a website, but the API hits the limit of 150 per hour. Is there any way to cache the Tweets and still use this widget? Or does anyone know of a good widget that caches, or simple code? If anyone knows, please explain in newbie terms. Thanks a lot! I have a question about caching files, the way i have seen people do it on tutorials is they save the file to a cache/ folder if non exists, then check if it exists when the page loads so if it doesn't then load the file normally or if it does then include the cache/file but what is the difference? if the browser has to load the file every time someone goes to it so you cache it for better performance isn't including the cache/file just the exact same thing? the server still has to download the included cached file. |