include("conn/conn.php");
$id=$_GET[id];
$tupian=$_GET[tupian];
$user = new shanchu();
$user->delFileUnderDir();
$sql=mysql_query("delete from image where id=$id");
class shanchu {
//循环目录下的所有文件
function delFileUnderDir( $dirName="../admin/upimages" )
{
if ( $handle = opendir( "$dirName" ) ) {
while ( false !== ( $item = readdir( $handle ) ) ) {
if ( $item != "." && $item != ".." ) {
if ( is_dir( "$dirName/$item" ) ) {
delFileUnderDir( "$dirName/$item" );
} else {
if( unlink( "$dirName/$item" ) )
echo "<script>alert('该信息已经删除!');window.location.href='delete.php?type=$type';</script>";
}
}
}
closedir( $handle );
}
}
}
?>
现在是删除文件夹下的所以文件,我想要的是单个文件的删除操作。
还有帮忙加下数据库字段的删除结合。
回复讨论(解决方案)
http://www.phpthinking.com/archives/238 可以参考下
可以在我发的代码的基础下改吗?
首先你需要找出所有文件,然后列表出来
例如
file1 删除
file2 删除
file3 删除
file4 删除
点删除时,把文件名称带过去。例如删除
接受到filename之后,使用unlink($filename);就可以删除单个文件了。
删除单个文件示例
//显示页面设置
if($_SESSION["tb_forum_name"]==""){//记录登陆名信息
echo "<script>alert('禁止非法登录!');window.location.href='hlogin.php';</script>";
exit;
}else{
?>
//查询数据库数据表信息
if($page){
$page_size=6; //每页显示2条记录
$query="select count(*) as total from tb_photo where up_id"; //从数据库中读取数据
$result=mysql_query($query);
$message_count=mysql_result($result,0,"total"); //获取总的记录数
$page_count=ceil($message_count/$page_size); //获取总的页数
$offset=($page-1)*$page_size;
$query=mysql_query("select * from tb_photo where up_id order by up_id desc limit $offset, $page_size");
while($myrow=mysql_fetch_array($query)){
?>
//这里就表示图片设置信息其他信息(略)

//点击删除按钮,根据其点击的ID号发送的删除页面处理删除这一条数据信息
&&picpath=" class="STYLE1">删除图片信息
//接收选择ID号删除相应的数据库中的数据
$delete_id=$_GET[delete_id];//接收要删除的ID号
$picpath='../'.$_GET[picpath];//删除保存在目录中和数据库同时保存的图片
$former = substr(strrchr($picpath,'/'),1);//设置保存的图片路径
if(file_exists($picpath)){
unlink($picpath);//查询处理图片保存的路径信息
}//CodeGo.net/
$query=mysql_query("delete from tb_photo where up_id='$delete_id'");//根据数据库信息查询要删除的数据ID
if($query==true){//如果存在数据就执行删除
echo "<script>alert('删除成功!');history.back();</script>";
}else{
echo "<script>alert('删除失败!');history.back();</script>";
}//注意:table信息(省略)
?>

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)