dounianluo0086 2014-01-23 04:31
浏览 19
已采纳

PHP复制和取消链接被忽略

This code runs when a user hits a delete button on my form. I am trying to copy a file, $picfile, from "/pics/" to "/pics/deletedrecordpics/" and then delete the orginal. Finally, delete the record from the database. Deleting the record from the databse works, but copying the file and deleting the original does nothing. There are no errors in the error log, so I am really confused as to why this code isn't running as I think it should.

if ($allowdelete==true && $thepassword == $password)
{
    //delete record that delete was set to by button

    //$sql = ("DELETE FROM $table WHERE id=$id");
    $sql = ("select picfile,title,author from $table where id=$delete");
    $file=mysql_query($sql);
    $resrow = mysql_fetch_row($file);
    $picfile = $resrow[0];
    $title = $resrow[1];
    $author = $resrow[2];
    if (file_exists("/pics".$picfile)){
        copy("/pics/".$picfile,"/pics/deletedrecordpics/".$author."-".$title."-".$picfile);
        unlink("/pics/".$picfile);
        echo $available = "image is available.";

        $sql = ("DELETE FROM $table WHERE id=$delete");
        $result = mysql_query($sql);

        if ($result){
            echo "Your Picture has been removed from our system.";
            Die($available);
        }
        else{
            echo "There was an error in removing your picture.";
            $Delete = "";
            Die();
        }       
    }
    else{
        echo $available = "image is not available.";
    }
}

The weird part is a have almost the same code in a delete button on my control panel located in "/adminpanel" and it works perfectly. The code for that is the same except I use $id instead $delete and "../" before all the "pics/" because it's in the adminpanel folder. The permissions are right and the folder exists because the code works with that page. And I know $delete is getting set because the record gets deleted from the database. I know picfile, author and title are getting set because I appended them to the print statement and they were all right. Really confused. Any ideas?

Here is the code for the working page

q = ("select picfile,title,author from $table where id=$id");
$file=mysql_query($q);
$resrow = mysql_fetch_row($file);
$picfile = $resrow[0];
$title = $resrow[1];
$author = $resrow[2];
copy("../pics/".$picfile,"../pics/deletedrecordpics/".$author." - ".$title." -     ".$picfile);
unlink("../pics/".$picfile);
$file=mysql_query($q);
$q = ("DELETE FROM $table WHERE id=$id");
$file=mysql_query($q);
  • 写回答

2条回答 默认 最新

  • dqby43944 2014-01-23 13:10
    关注

    Try this

    $file_path = $_SERVER["DOCUMENT_ROOT"]."/pics/";
    if (file_exists($file_path.$picfile))
    {
        copy($file_path.$picfile, $file_path."/deletedrecordpics/".$author."-".$title."-".$picfile);
        unlink($file_path.$picfile);
    }
    else
    {
            echo "File not found!!!!!!!!";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)