zy221021 2019-04-13 23:42 采纳率: 0%
浏览 115

求助asp代码改写成php代码

<%

function delete_file(src)

set fso=server.createobject("scripting.filesystemobject")

if src<>"" then
myfile=server.mappath(src)

if fso.FileExists(myfile) then

fso.DeleteFile myfile

end if

end if

set fso=nothing

end function

kind=request.form("kind")

id=request.form("id")

select case kind

case "news"

sql="delete from news where id="&id

conn.execute(sql)

case "menu"

sql="delete from menu where id="&id

conn.execute(sql)

case "picnews"

    set rs=server.createobject("adodb.recordset")
    sql="select * from picnews where id="&id
    rs.open sql,conn,1,3
    src=rs("src")
    delete_file(src)
    rs.delete
    rs.update
    rs.close
    set rs=nothing

case "pic"

    set rs=server.createobject("adodb.recordset")
    sql="select * from picvideo where id="&id
    rs.open sql,conn,1,3
    src=rs("upfile")
    delete_file(src)
    rs.delete
    rs.update
    rs.close
    set rs=nothing

case "page"

    set rs=server.createobject("adodb.recordset")
    sql="select content from cont where id="&id
    rs.open sql,conn,1,3
    content=rs("content")
    set re=new regexp
    re.pattern="upload\/\d{17}\.\w{3,4}"
    re.global=true
    re.ignoreCase=true
    if re.Test(content) then
        set matches=re.execute(content)
        for each match in matches   
        filename=match.value
        delete_file(filename)
        '删除数据库中上传文件记录
        'conn.execute ("delete from uploadfile where filename='"&filename&"'")
        next
    end if
    set re=nothing
    rs.delete
    rs.update       
    rs.close
    set rs=nothing

end select

conn.close

set conn=nothing

response.write("ok")

%>

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-08 22:08
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    以下是将ASP代码转换为PHP的示例:

    <?php
    function delete_file($src)
    {
        $fso = new FSObject();
    
        if ($src != "") {
            $myfile = $fso->GetPathFromServer($src);
    
            if ($fso->FileExists($myfile)) {
                $fso->DeleteFile($myfile);
            }
        }
    
        $fso = null;
    }
    
    $kind = $_REQUEST['kind'];
    $id = $_REQUEST['id'];
    
    switch ($kind) {
        case "news":
            $sql = "DELETE FROM news WHERE id=$id";
            $conn = new ADODBConnection();
            $conn->Open('Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=<PASSWORD>');
            $conn->Execute($sql);
            break;
    
        case "menu":
            $sql = "DELETE FROM menu WHERE id=$id";
            $conn = new ADODBConnection();
            $conn->Open('Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=<PASSWORD>');
            $conn->Execute($sql);
            break;
    
        case "picnews":
            $sql = "DELETE FROM picnews WHERE id=$id";
            $conn = new ADODBConnection();
            $conn->Open('Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=<PASSWORD>');
            $conn->Execute($sql);
            break;
    
        case "pic":
            $sql = "DELETE FROM picvideo WHERE id=$id";
            $conn = new ADODBConnection();
            $conn->Open('Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=<PASSWORD>');
            $conn->Execute($sql);
            break;
    
        case "page":
            $sql = "SELECT content FROM cont WHERE id=$id";
            $conn = new ADODBConnection();
            $conn->Open('Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=<PASSWORD>');
            $rs = $conn->Query($sql);
            $matches = array();
            while ($row = $rs->Read()) {
                $filename = $row["filename"];
                delete_file($filename);
            }
            $rs->Close();
            $conn->Close();
            break;
    }
    $conn->Close();
    $response->Write("ok");
    ?>
    

    请注意,此代码中的FSObjectADODBConnection是替代库,用于模拟ASP.NET File System对象和ADO Connection。在实际应用中,请使用与服务器兼容的替代库替换它们。

    此外,PHP脚本还包含了处理图片上传功能的部分代码,但是由于缺少必要的数据验证、错误处理等细节,这个部分可能会导致错误或不一致的结果。根据你的具体需求,可能需要进一步扩展这个代码来满足这些要求。

    评论

报告相同问题?

悬赏问题

  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振