Log in

View Full Version : Copy files for backup



jtf107
10-26-2010, 09:48 PM
I have a file on my website that I need to make a backup of every 30min. So what I was going to do is make a cron job and have it run a php script that would make a copy of a file. I tried:

<?php
$file = 'entries.txt';
$newfile = 'backup.txt.bak';

if (!copy($file, $newfile)) {
echo "failed to copy $file";
}
?>

but that is disabled for security purposes.

I just started out with php and dont really know that much, so could someone please guide me to completing this task?

djr33
10-26-2010, 10:55 PM
If that's disabled then other similar functions might be disabled. fwrite() and related functions could do this, or you could try exec() and other system functions to run linux commands directly-- if these aren't also disabled.

If you run phpinfo(); (on an otherwise empty page) you may get some feedback about what is and what is not allowed.

jtf107
10-26-2010, 11:02 PM
Better yet... How could I email the file to my self. (attaching a file in the mail function)?

djr33
10-27-2010, 12:44 AM
That's very complex. There are lots of tutorials for it but it's not something I'd recommend for a beginner (as you said in your last post).

If you need this right now, I'd suggest looking for an existing script, though many may rely on other functions that are disabled-- you may need to get a different hosting account that allows full access. It shouldn't be hard to find one for about $5-10/mo (and up).