Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Any know php? :P ENTER :P
11-04-2013, 12:25 PM, (This post was last modified: 11-04-2013, 12:25 PM by sathwik.)
Post: #1
Any know php? :P ENTER :P
B-) watz code to delete files in directory older than 2 days?
Reply
11-04-2013, 02:55 PM,
Post: #2
RE: Any know php? :P ENTER :P
<?php
$dir ="Path_to_Directory_on_SerVeR";
foreach(glob($dir."*")as $file){
if(filemtime($file)> time()-172800){ unlink($file); } }
?>

You can also specify file type by adding an extension after the * (wildcard) e.g.

For jpg images use: glob($dir."*.jpg")

For txt files use: glob($dir."*.txt")

For htm files use:glob($dir."*.htm")
Visit https://www.codecyan.com if you need WEBSITE or MOBILE APP or any web services.
Reply
11-05-2013, 07:37 AM, (This post was last modified: 11-05-2013, 07:46 AM by sathwik.)
Post: #3
RE: Any know php? :P ENTER :P
I think unlinking willn't decrease disk space :-( and path mean
Code:
/home/user/public_html/folder
?

Code:
<?php
$dir ="Path_to_Directory_on_SerVeR";
foreach(glob($dir."*.mp3")as $file){
if(filemtime($file)> time()-172800){ delete($file); } }
?>
wat abt this?
Reply
11-05-2013, 07:56 AM, (This post was last modified: 11-05-2013, 07:58 AM by OMi.)
Post: #4
RE: Any know php? :P ENTER :P
Yupe.. And 'Path' is folder name, from which you want to delete files..

Only folder name, for e.g. if you want to delete files located within public_html named 'data' then $dir = "data"; I hope you got it :p
Visit https://www.codecyan.com if you need WEBSITE or MOBILE APP or any web services.
Reply
11-05-2013, 08:02 AM,
Post: #5
RE: Any know php? :P ENTER :P
Ok :-D i waz confused by ur wrd 'server' :-D wat abt 'delete' rather than 'unlink'
Reply
[-] The following 1 user Likes sathwik's post:
  • OMi
11-05-2013, 09:15 AM,
Post: #6
RE: Any know php? :P ENTER :P
It might not work correctly.. :v
Visit https://www.codecyan.com if you need WEBSITE or MOBILE APP or any web services.
Reply
11-05-2013, 10:18 AM,
Post: #7
RE: Any know php? :P ENTER :P
Then wat can i do?
Reply
11-05-2013, 02:00 PM, (This post was last modified: 11-05-2013, 02:00 PM by OMi.)
Post: #8
RE: Any know php? :P ENTER :P
Just kidding.. Above code works fine and don't eat up disk space :v
Visit https://www.codecyan.com if you need WEBSITE or MOBILE APP or any web services.
Reply
11-05-2013, 02:23 PM,
Post: #9
RE: Any know php? :P ENTER :P
delete() is not a real function. its a dummy function name for people
"trying" to find the unlink function while searching php.net/
as stated here: http://us2.php.net/delete

the correct function is what omi posted originally.
unlink()
found here: http://us2.php.net/manual/en/function.unlink.php
Reply
[-] The following 1 user Likes Ghost's post:
  • OMi
11-05-2013, 09:28 PM, (This post was last modified: 11-05-2013, 09:30 PM by sathwik.)
Post: #10
RE: Any know php? :P ENTER :P
Code:
<?php
$expiretime=172800;
$tmpFolder="datas/";
$fileTypes="*.mp3";
foreach  (glob($tmpFolder . $fileTypes) as $Filename2) {
echo "$Filename2<br>";
// Read file  creation time
$FileCreationTime =  filectime($Filename2);
//
$FileAge = time() - $FileCreationTime;
if ($FileAge >  ($expiretime *  60)){
//print "The file $Filename2 is older than $expire_time  minutes\n"
delete($Filename2);
}
}
?>
codded by me B-) i think it will wrk

And as far as i know B-) therez no use of unlink B-)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)