簡體   English   中英

PHP從file_get_contents(“ php:// input”)獲取圖像尺寸

[英]PHP get image dimensions from file_get_contents(“php://input”)

由於上載腳本,我無法通過$ _FILE變量獲取上載的文件,因此我必須解決

$file = file_get_contents("php://input")

我想獲取尺寸(如果它是圖像),為此,我將使用getimageresize(),但getimageresize()僅采用文件而不是字符串。 這就是我的問題。 我該如何解決?

$image = imagecreatefromstring($img_str);
$w = imagesx($image);
$h = imagesy($image);

嘗試這個

<?php
    $imagesize = getimagesize($image_string);
    echo 'Width: ' . $imagesize[0] . ' pixels<br />';
    echo 'Height: ' . $imagesize[1] . 'pixels';
?>

我正在使用功能getimagesize() 看看PHP.net上的文檔: http : //nl.php.net/manual/en/function.getimagesize.php

用php:// input打開的流只能讀取一次; 該流不支持搜索操作。 但是,根據SAPI的實現,有可能打開另一個php:// input流並重新開始讀取。 僅在請求正文數據已保存的情況下才有可能。 通常,POST請求就是這種情況,而其他請求方法(例如PUT或PROPFIND)則不是這種情況。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM