My client wants to back up her files on the server hosting her website. (Against my recommendation.)
Nevertheless, I am trying to make an interface where she can do this. Works great on UNIX, her site is hosted on Windows. For this reason, my "unlink ()" function will not work. What can I do?
I am new to programming in general, and PHP in particular, so I will need to be "baby-stepped" through this.
Here is the code as it now stands (thanks for any help/suggestions):
<HEAD>
<TITLE>Viewing Files in a Directory</TITLE>
</HEAD>
<BODY>
<TABLE BORDER=0 WIDTH="100%" CELLSPACING=2 CELLPADDING=2 ALIGN=CENTER>
<?php
/ This file lists all the information for files in a directory and allows the user to delete, upload and rename files.
/
if ($Upload) { // Handle file uploads.
print ("<TR><TD COLSPAN=4 ALIGN=left>Uploaded file name: $File_name</TD></TR>\n");
print ("<TR><TD COLSPAN=4 ALIGN=left>Uploaded file size: $File_size</TD></TR>\n");
if (copy ($File, "files/$File_name")) {
print ("<TR><TD COLSPAN=4 ALIGN=left>Your file, $File_name, was successfully uploaded!</TD></TR>\n");
} else {
print ("<TR><TD COLSPAN=4 ALIGN=left>Your file, $File_name, could not be copied.</TD></TR>\n");
}
@unlink ($File);
print ("<TR><TD COLSPAN=4 ALIGN=left> </TD></TR>\n");
}
if ($Delete) { // Handle file deletions.
for ($i = 0; $i < count ($Delete); $i++) {
if ( @unlink ("files/$Delete[$i]") ) {
print ("<TR><TD COLSPAN=4 ALIGN=left>Your file, $Delete[$i], was successfully deleted!</TD></TR>\n");
} else {
print ("<TR><TD COLSPAN=4 ALIGN=left>Your file, $Delete[$i], could not be deleted.</TD></TR>\n");
}
}
print ("<TR><TD COLSPAN=4 ALIGN=left> </TD></TR>\n");
}
if ($Rename) { // Handle file renaming.
for ($n = 0; $n < count ($Rename); $n++) {
$OldFilename = $Rename[$n];
$Old = "files/$OldFilename";
$New = "files/$NewName[$OldFilename]";
if ( rename ($Old, $New) ) {
print ("<TR><TD COLSPAN=4 ALIGN=left>Your file, $Rename[$n], was successfully renamed!</TD></TR>\n");
} else {
print ("<TR><TD COLSPAN=4 ALIGN=left>Your file, $Rename[$n], could not be renamed.</TD></TR>\n");
}
}
print ("<TR><TD COLSPAN=4 ALIGN=left> </TD></TR>\n");
}
// Start the form.
print ("<FORM ACTION=\"files.php\" METHOD=POST ENCTYPE=\"multipart/form-data\">\n");
print ("<TR><TD><B>File Name</B></TD><TD><B>File Size</B></TD><TD><B>Delete</B></TD><TD><B>Rename</B> (Enter the New Name in the Box)</TD></TR>\n");
// Read the files from the directory.
$Open = opendir ("files");
while ($Files = readdir ($Open)) {
$Filename = "files/" . $Files;
if (is_file ($Filename)) {
$Size = filesize ("files/$Files");
print ("<TR><TD><a href=\"http://www.aandpbusinesssolutions.com/admin/files/$Files\">$Files</a></TD><TD>$Size</TD><TD><INPUT TYPE=CHECKBOX NAME=\"Delete[]\" VALUE=\"$Files\"></TD><TD><INPUT TYPE=CHECKBOX NAME=\"Rename[]\" VALUE=\"$Files\"><INPUT TYPE=TEXT NAME=\"NewName[$Files]\"></TD></TR>\n");
}
}
closedir ($Open);
// Give the upload option.
print ("<TR><TD COLSPAN=4 ALIGN=left> </TD></TR>\n");
print ("<TR><TD COLSPAN=4 ALIGN=left><INPUT TYPE=CHECKBOX NAME=\"Upload\" VALUE=\"Yes\">Upload a file to theserver:<INPUT TYPE=FILE NAME=\"File\" SIZE=20></TD></TR>\n");
print ("<TR><TD COLSPAN=4 ALIGN=left><INPUT TYPE=SUBMIT NAME=\"SUBMIT\" VALUE=\"Submit!\"></FORM></TD></TR>\n");
?>
</TABLE>
</BODY>