Php 未知脚本正在随机删除目录
我已经为我的朋友建立了一个简单的“Facebook”式的时间线系统,让他能够上传状态和图片,让他的用户看到。虽然存储图像的文件不断被删除,但它似乎都工作得很好,而且我似乎不是故意造成问题的,所以我不知道删除这个目录是什么 我在下面添加了上传/删除脚本,看看是否有人可以在这里帮助我?我似乎找不到脚本的任何部分可以单独删除主映像目录 请记住-这仍然是未完成的,远不是安全的,只是还没有,我们在测试阶段,需要解决这个问题,然后我才能完善系统的工作 存储图像的主文件夹是Php 未知脚本正在随机删除目录,php,image,mysqli,directory,Php,Image,Mysqli,Directory,我已经为我的朋友建立了一个简单的“Facebook”式的时间线系统,让他能够上传状态和图片,让他的用户看到。虽然存储图像的文件不断被删除,但它似乎都工作得很好,而且我似乎不是故意造成问题的,所以我不知道删除这个目录是什么 我在下面添加了上传/删除脚本,看看是否有人可以在这里帮助我?我似乎找不到脚本的任何部分可以单独删除主映像目录 请记住-这仍然是未完成的,远不是安全的,只是还没有,我们在测试阶段,需要解决这个问题,然后我才能完善系统的工作 存储图像的主文件夹是post_images,这是正在删除
post_images
,这是正在删除的目录
删除目录功能-
function rrmdir($dir) {
foreach(glob($dir . '/*') as $file) {
if(is_dir($file)) rrmdir($file); else unlink($file);
}
rmdir($dir);
}
减少职位-
if(isset($_GET['decline_post'])){
$post_id = $conn->real_escape_string($_GET['decline_post']);
$getimagefolder = mysqli_fetch_assoc(mysqli_query($conn, "SELECT `post_image_folder` FROM `Pto6LsuQ_posts` WHERE `post_id` = '$post_id'"));
$image_folder = $getimagefolder['post_image_folder'];
mysqli_query($conn,"DELETE FROM `Pto6LsuQ_posts` WHERE `post_id` = '$post_id'");
$direc = 'post_images/'.$image_folder;
if (file_exists($direc)) {
rrmdir($direc);
} else {
}
header("Location: members_area.php");
}
删除帖子-
if(isset($_GET['delete_post'])){
$post_id = $conn->real_escape_string($_GET['delete_post']);
$getimagefolder = mysqli_fetch_assoc(mysqli_query($conn, "SELECT `post_image_folder` FROM `Pto6LsuQ_posts` WHERE `post_id` = '$post_id'"));
$image_folder = $getimagefolder['post_image_folder'];
mysqli_query($conn,"DELETE FROM `Pto6LsuQ_posts` WHERE `post_id` = '$post_id'");
$direc = 'post_images/'.$image_folder;
if (file_exists($direc)) {
rrmdir($direc);
} else {
}
header("Location: members_area.php");
}
上传帖子-
if(isset($_POST['new_post'])){
$post_status = $conn->real_escape_string($_POST['status']);
$user_id = $_SESSION['user_id'];
if(!empty($_FILES['images']['tmp_name'])){
$length = 9;
$search = true; // allow the loop to begin
while($search == true) {
$rand_image_folder = substr(str_shuffle("0123456789"), 0, $length);
if (!file_exists('../post_images/'.$rand_image_folder)) {
$search = false;
}
}
mkdir("../post_images/".$rand_image_folder);
foreach($_FILES['images']['tmp_name'] as $key => $tmp_name ){
$file_name = $key.$_FILES['images']['name'][$key];
$file_size = $_FILES['images']['size'][$key];
$file_tmp = $_FILES['images']['tmp_name'][$key];
$file_type = $_FILES['images']['type'][$key];
$check_file_type = substr($file_type, 0, strrpos( $file_type, '/'));
if($check_file_type !== 'image'){
header('Location: ../members_area.php?posterror=1');
}
$extensions = array("jpeg","jpg","png","JPEG","JPG","PNG");
$format = trim(substr($file_type, strrpos($file_type, '/') + 1));
if(in_array($format,$extensions) === false){
header('Location: ../members_area.php?posterror=1');
} else {
move_uploaded_file($file_tmp,"../post_images/".$rand_image_folder."/".$file_name);
$file = "../post_images/".$rand_image_folder."/".$file_name;
$cut_name = substr($file, strpos($file, "/") + 1);
$cut_name = explode('/',$cut_name);
$cut_name = end($cut_name);
$newfile = "../post_images/".$rand_image_folder."/thb_".$cut_name;
$info = getimagesize($file);
list($width, $height) = getimagesize($file);
$max_width = '350';
$max_height = '250';
//try max width first...
$ratio = $max_width / $width;
$new_width = $max_width;
$new_height = $height * $ratio;
//if that didn't work
if ($new_height > $max_height) {
$ratio = $max_height / $height;
$new_height = $max_height;
$new_width = $width * $ratio;
}
if ($info['mime'] == 'image/jpeg') $image = imagecreatefromjpeg($file);
elseif ($info['mime'] == 'image/gif') $image = imagecreatefromgif($file);
elseif ($info['mime'] == 'image/png') $image = imagecreatefrompng($file);
$image = imagecreatetruecolor($new_width, $new_height);
$photo = imagecreatefromjpeg($file);
imagecopyresampled($image, $photo, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image, $newfile, 70);
}
}
if($account_type < 4){
$post_public = 1;
} else {
$post_public = 0;
}
mysqli_query($conn,"INSERT INTO `Pto6LsuQ_posts`
(post_id,post_user_id,post_date_time,post_status,post_image_folder,post_likes,post_public_status)
VALUES ('','$user_id',NOW(),'$post_status','$rand_image_folder','0','$post_public')");
} else {
if($account_type < 4){
$post_public = 1;
} else {
$post_public = 0;
}
mysqli_query($conn,"INSERT INTO `Pto6LsuQ_posts`
(post_id,post_user_id,post_date_time,post_status,post_image_folder,post_likes,post_public_status)
VALUES ('','$user_id',NOW(),'$post_status','','0','$post_public')");
}
header('Location: ../members_area.php?posterror=2');
}
if(isset($\u POST['new\u POST'])){
$post_status=$conn->real_escape_字符串($_post['status']);
$user\u id=$\u会话['user\u id'];
如果(!空($_文件['images']['tmp_名称]])){
$length=9;
$search=true;//允许循环开始
while($search==true){
$rand_image_folder=substr(str_shuffle(“0123456789”),0,$length;
如果(!file_存在('../post_images/'.$rand_image_folder)){
$search=false;
}
}
mkdir(“../post_images/”$rand_image_文件夹);
foreach($\u文件['images']['tmp\u name']作为$key=>$tmp\u name){
$file\u name=$key.$\u文件['images']['name'][$key];
$file\u size=$\u文件['images']['size'][$key];
$file\u tmp=$\u FILES['images']['tmp\u name'][$key];
$file\u type=$\u文件['images']['type'][$key];
$check_file_type=substr($file_type,0,strrpos($file_type,'/'));
如果($check\u file\u type!==“image”){
标题('Location:../members\u area.php?posterror=1');
}
$extensions=数组(“jpeg”、“jpg”、“png”、“jpeg”、“jpg”、“png”);
$format=trim(substr($file_-type,strrpos($file_-type,“/”)+1));
if(在数组($format,$extensions)==false中){
标题('Location:../members\u area.php?posterror=1');
}否则{
移动上传的文件($file\u tmp,“../post\u images/”$rand\u image\u folder.“/”$file\u name);
$file=“../post_images/”$rand_image_folder./“$file_name;
$cut_name=substr($file,strpos($file,“/”)+1);
$cut_name=分解(“/”,$cut_name);
$cut\u name=结束($cut\u name);
$newfile=“../post_images/”$rand_image_folder./thb_u.“../cut_name;
$info=getimagesize($file);
列表($width,$height)=getimagesize($file);
$max_width='350';
$max_height='250';
//首先尝试最大宽度。。。
$ratio=$max_width/$width;
$new_width=$max_width;
$new_height=$height*$比率;
//如果那没用的话
如果($new\u height>$max\u height){
$ratio=$max_height/$height;
$new_height=$max_height;
$new_width=$width*$比率;
}
如果($info['mime']=='image/jpeg')$image=imagecreatefromjpeg($file);
elseif($info['mime']=='image/gif')$image=imagecreatefromformgif($file);
elseif($info['mime']=='image/png')$image=imagecreatefrompng($file);
$image=imageCreateTureColor($new\u宽度,$new\u高度);
$photo=imagecreatefromjpeg($file);
imagecopyresampled($image、$photo、0、0、0、0、$new\u width、$new\u height、$width、$height);
imagejpeg($image,$newfile,70);
}
}
如果($账户类型<4){
$post_public=1;
}否则{
$post_public=0;
}
mysqli_查询($conn,“插入'Pto6LsuQ_帖子'
(发布id、发布用户id、发布日期时间、发布状态、发布图像文件夹、发布喜欢、发布公共状态)
值(“”,$user_id',NOW(),“$post_status”,“$rand_image_folder”,“0”,“$post_public”);
}否则{
如果($账户类型<4){
$post_public=1;
}否则{
$post_public=0;
}
mysqli_查询($conn,“插入'Pto6LsuQ_帖子'
(发布id、发布用户id、发布日期时间、发布状态、发布图像文件夹、发布喜欢、发布公共状态)
值(“”,$user_id',NOW(),$post_status',“”,'0','$post_public');
}
标题('Location:../members\u area.php?posterror=2');
}
$direc='post\u images/'的值是多少。$image\u文件夹代码>?当您回显此变量时,$direc
它返回什么?它似乎返回为null,因为主文件夹是deletedIt,它应该返回对MySQLi数据库表查询的搜索结果,并生成存储图像的文件夹的ID。虽然我可以看到,如果搜索返回负数,那么当您回显此$direc
时,该值将返回为null?输出是什么