File copy and delete functions
1, modify the front-end code
Add get parameters to the copy and delete buttons respectively, so that they can send the file id ( file) and action type action

The code is as follows:
<?php <a href="?file=<?php echo $v['file_id'];?>&action=copy">复制</a>| <a href="?file=<?php echo $v['file_id'];?>&action=del">删除</a>
2, get the get parameters for copy and delete operations
First obtain the get parameter file_id in index.php, then query the file table netdisk_file, and obtain the corresponding file information that needs to be copied and deleted.
Perform the copy operation of the file copy() and delete operation unlink()
The code is as follows:
<?php
//获取get参数
$file_id=isset($_GET['file'])?intval($_GET['file']):0;
//复制和删除功能
$action=isset($_GET['action'])?trim($_GET['action']):"";
if($action=="del"){
// unset();
$sql="select *from netdisk_file where file_id=$file_id";
$del_file=fetchRow($sql);
unlink($del_file['file_save']);
//删除数据库里的数据
$sql="delete from netdisk_file where file_id=$file_id";
if(!mysql_query($sql)){
echo '数据库数据删除失败';
};
}elseif ($action=="copy"){
$sql="select *from netdisk_file where file_id=$file_id";
$copy_file=fetchRow($sql);
$filesavename=$copy_file['file_save'];
if(file_exists("$filesavename.bak")){
echo '文件名冲突,复制失败';
}
if(!copy("$filesavename","$filesavename.bak")){
echo "复制失败";
}else{
$file_copy_name=$copy_file["file_name"];
$file_copy_size=$copy_file["file_size"];
$file_copy_id=$copy_file["folder_id"];
$sql="insert into netdisk_file (file_name,file_save,file_size,file_time,folder_id) values('$file_copy_name.bak','$filesavename.bak',$file_copy_size,now(),$file_copy_id)";
if(!mysql_query($sql)){
unlink($uploadfile_save);
echo "写入数据库出错";
}
}
}3, effect display
Copy display:
Click the page before copying:

Click to finish After copying:

Changes in the database:
Delete display:
Page before deletion:

Page after deletion:

##Corresponding database Changes have also occurred


