简体   繁体   English

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

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

My goal is to simply echo $_POST['imageVar']; 我的目标是简单地回显$ _POST ['imageVar']; back with content headers as a quick and dirty means to "export" an image from a flash application. 返回内容标题作为快速和脏的方法从Flash应用程序“导出”图像。 I saw an example of this as follows, but it does not work with my php version/config: 我看到了如下的示例,但它不适用于我的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;
}

So as a work around I created a script that saves the image to the server, reads the image and echos it back, then deletes the image. 因此,作为解决方法,我创建了一个脚本,将图像保存到服务器,读取图像并回显它,然后删除图像。 I don't like this approach as I need to have a directory that is writable by the apache user (im on a shared server). 我不喜欢这种方法,因为我需要一个可由apache用户写入的目录(在共享服务器上)。 Is there a way to accomplish what I am doing here without hte need to use the temp file? 有没有办法在不需要使用临时文件的情况下完成我在这里做的事情?

<?
$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";
}

?> ?>

Any input or ideas greatly appreciated! 任何输入或想法非常感谢! Thanks for looking 谢谢你的期待

You can just use: 你可以使用:

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

No need to move it if you're not going to keep it. 如果你不打算保留它,就不需要移动它。

On a side note, regarding the first solution you were looking at, does an echo file_get_contents('php://input'); 在旁注中,关于您正在查看的第一个解决方案,是否有一个echo file_get_contents('php://input'); not work? 不行?

$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;

What about that? 那个怎么样?

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

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