为了更好的对网站进行管理,本章节讲解如何在服务器复制、移动、删除操作。
copy()函数主要用于复制文件。copy成功时返回 TRUE, 或者在失败时返回 FALSE。
bool copy ( string $source , string $dest [, resource $context ] ) copy ("源文件路径","目标路径") |
copy.php文件
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><head><title>复制文件-炫代码</title></head>
<body>
<table post" action="">
<form name="form1" method="post" action="">
<tr>
<td rowspan="2" align="center">复制文件</td>
<td align="right" valign="bottom">要复制文件:</td>
<td height="39" valign="bottom">
<input name="copy" type="text" size="33"></td>
<td rowspan="2" align="left">
<input type="submit" name="Sub" value="复制"></td>
</tr>
<tr>
<td align="right" valign="top">文件复制到:</td>
<td height="41" valign="top">
<input name="copyto" type="text" size="33"></td>
</tr>
<tr>
<td colspan="4" align="center">例如:D:\XXX\XXX.txt</td>
</tr>
</form>
</table>
<?php
if (isset($_POST ['Sub'])) {
$copy = $_POST ['copy'];
$copyto = $_POST ['copyto'];
if (copy ( $copy, $copyto )) {
echo "<script>alert('复制成功!!');</script>";
} else {
echo "<script>alert('复制失败!!');</script>";
}
}
?>
</body></html>rename()函数主要用于文件移动,也可以用于重命名。
bool rename ( string $oldname , string $newname [, resource $context ] ) rename ("旧文件名","新文件名") |
reanme.php文件
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><head><title>移动文件-炫代码</title></head>
<body>
<table post" action="">
<form name="form1" method="post" action="">
<tr>
<td rowspan="2" align="center">移动文件</td>
<td align="right" valign="bottom">要移动文件:</td>
<td height="39" valign="bottom">
<input name="move" type="text" size="33"></td>
<td rowspan="2" align="left">
<input type="submit" name="Sub" value="移动"></td>
</tr>
<tr>
<td align="right" valign="top">文件移动到:</td>
<td height="41" valign="top">
<input name="moveto" type="text" size="33"></td>
</tr>
<tr>
<td colspan="4" align="center">例如:D:\XXX\XXX.txt</td>
</tr>
</form>
</table>
<?php
if (isset($_POST ['Sub'])) {
$move = $_POST ['move'];
$moveto = $_POST ['moveto'];
if (rename ( $move, $moveto )) {
echo "<script>alert('移动成功!!');</script>";
} else {
echo "<script>alert('移动失败!!');</script>";
}
}
?>
</body></html>主要用于删除服务器文件。在成功时返回true,在失败时返回false。
bool unlink ( string $filename [, resource $context ] ) unlink ("文件名") |
unlink.php文件
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><head><title>删除文件-炫代码</title></head>
<body>
<table post" action="">
<form name="form1" method="post" action="">
<tr>
<td align="center">删除文件:</td>
<td><input name="delete" type="text" size="32">
<input type="submit" name="Sub" value="删除"></td>
</tr>
<tr>
<td colspan="4" align="center">例如:D:\XXX\XXX.txt</td>
</tr>
</form>
</table>
<?php
if (isset($_POST ['Sub'])) {
$delete = $_POST ['delete'];
if (unlink ( $delete )) {
echo "<script>alert('删除成功!!');</script>";
} else {
echo "<script>alert('删除失败!!');</script>";
}
}
?>
</body></html>