duanqian6295 2013-06-06 01:59
浏览 26
已采纳

将PHP字符串导出到文件时出错[关闭]

I have a website, where the user can write PHP/HTML code and save it to his computer. Everything is fine until the user types a slash (/).

The file saves into the client computer, but instead of saving the client code, it exports an PHP error (the file in the computer has a PHP code of an error). The file-saving code is the following:

$content = $_REQUEST['code'];   //Get the code

$file = "file.php";
file_put_contents($file, $content); //Writes the content into a file

header('Content-type: text/plain');
header('Content-Disposition: attachment; filename=$file');
readfile(dirname(dirname($con)) . '/'.$file);

The error only happens when the client uses slashes. Any idea on why is this happening? )-:

EDIT:

This is one of those errors:

enter image description here

The code that i tried to export was the following:

/:

The thing that worries me, is that if I type exactly the same characters in different order (:/) then they export to my computer with no errors.

  • 写回答

1条回答 默认 最新

  • douhuanqiao5290 2013-06-06 16:04
    关注

    I see only one error - problem with readfile(\/105.2.php) in line 24 - so I tested it.

    $file = 'file.php';
    $con = '/:';
    readfile(dirname(dirname($con)) . '/'.$file);
    

    It gives me incorrect path \/file.php as in error message.

    If I use $con=':/' it gives me correct path ./file.php

    I only don't know what $con is. Maybe you have dirname(dirname($content)) in your oryginal code and $content = $_REQUEST['code']; => dirname(dirname($_REQUEST['code'])) => dirname(dirname("/:")) => "\"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么shp文件会有这种小方块?
  • ¥15 ecplise在连接数据库时显示加载驱动成功但是数据库连接失败
  • ¥15 visionmaster启动失败,提示为“机器不满足授权而被禁用”
  • ¥50 用logisim设计16位单时钟周期cpu
  • ¥15 IDEA中圈复杂度如何具体设置
  • ¥50 labview采集不了数据
  • ¥15 Multisim红外倒车雷达仿真中距离问题
  • ¥15 请上面代码做什么处理或什么混淆
  • ¥15 英雄联盟自定义房间置顶
  • ¥15 W5500网线插上无反应