Post Reply 
 
Thread Rating:
  • 0 Votes - 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
cool watz code to delete files in directory older than 2 days?
Visit this user's website Find all posts by this user
Like Post Quote this message in a 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 www.CodeCyan.com if you want to build your own website. For any help, script, code and modifications. happy
Visit this user's website Find all posts by this user
Like Post Quote this message in a 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 sad 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?
Visit this user's website Find all posts by this user
Like Post Quote this message in a 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 tongue

Visit www.CodeCyan.com if you want to build your own website. For any help, script, code and modifications. happy
Visit this user's website Find all posts by this user
Like Post Quote this message in a reply
11-05-2013, 08:02 AM
Post: #5
RE: Any know php? :P ENTER :P
Ok big grin i waz confused by ur wrd 'server' big grin wat abt 'delete' rather than 'unlink'
Visit this user's website Find all posts by this user
Like Post Quote this message in a reply
[-] The following 1 user Likes sathwik's post:
OMi (11-05-2013)
11-05-2013, 09:15 AM
Post: #6
RE: Any know php? :P ENTER :P
It might not work correctly.. :v

Visit www.CodeCyan.com if you want to build your own website. For any help, script, code and modifications. happy
Visit this user's website Find all posts by this user
Like Post Quote this message in a reply
11-05-2013, 10:18 AM
Post: #7
RE: Any know php? :P ENTER :P
Then wat can i do?
Visit this user's website Find all posts by this user
Like Post Quote this message in a 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 www.CodeCyan.com if you want to build your own website. For any help, script, code and modifications. happy
Visit this user's website Find all posts by this user
Like Post Quote this message in a 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
Find all posts by this user
Like Post Quote this message in a reply
[-] The following 1 user Likes Ghost's post:
OMi (11-05-2013)
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 cool i think it will wrk

And as far as i know cool therez no use of unlink cool
Visit this user's website Find all posts by this user
Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)