繁体   English   中英

如何用PHP回显原始帖子数据?

[英]How to echo raw post data in PHP?

我的目标是简单地回显$ _POST ['imageVar']; 返回内容标题作为快速和脏的方法从Flash应用程序“导出”图像。 我看到了如下的示例,但它不适用于我的php版本/ config:

if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
    // get bytearray
    $jpg = $GLOBALS["HTTP_RAW_POST_DATA"];

    // add headers for download dialog-box
    header('Content-Type: image/jpeg');
    header("Content-Disposition: attachment; filename=".$_GET['name']);
    echo $jpg;
}

因此,作为解决方法,我创建了一个脚本,将图像保存到服务器,读取图像并回显它,然后删除图像。 我不喜欢这种方法,因为我需要一个可由apache用户写入的目录(在共享服务器上)。 有没有办法在不需要使用临时文件的情况下完成我在这里做的事情?

<?
$fileName = basename( $_FILES['uploadedfile']['name']);
$tempFile = "uploads/" . $fileName;
$fileSize = $HTTP_POST_FILES['uploadedfile']['size'];
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $tempFile)) {
        $fh = fopen($tempFile, 'r');
        $fileContents = fread($fh, $fileSize);


        header('Content-Type: image/jpeg');
        header("Content-Disposition: attachment; filename=$fileName");
        echo $fileContents;

        fclose($fh);
        unlink($tempFile);
} else {
        echo "upload fail";
}

?>

任何输入或想法非常感谢! 谢谢你的期待

你可以使用:

header('Content-Type: image/jpeg');
header("Content-Disposition: attachment; filename=$fileName")
readfile($_FILES['uploadedfile']['tmp_name']);

如果你不打算保留它,就不需要移动它。

在旁注中,关于您正在查看的第一个解决方案,是否有一个echo file_get_contents('php://input'); 不行?

$s = file_get_contents('php://input');

// add headers for download dialog-box
header('Content-Type: image/jpeg');
header("Content-Disposition: attachment; filename=".$_GET['name']);
echo $s;

那个怎么样?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM