Php将文件从url到blob转换为javascript

Php将文件从url到blob转换为javascript,javascript,php,laravel,blob,Javascript,Php,Laravel,Blob,我正在尝试将图像从url转换为可以在javascript中使用的blob文件,但我失败了,我如何才能做到这一点,或者这是否可能: 到目前为止,我已经做到了: // $request->location is the url to the file in this case an image $img = file_get_contents($request->location); $ch = curl_init(); // set URL and

我正在尝试将图像从url转换为可以在javascript中使用的blob文件,但我失败了,我如何才能做到这一点,或者这是否可能:

到目前为止,我已经做到了:

    // $request->location is the url to the file in this case an image
    $img = file_get_contents($request->location);

    $ch = curl_init();

    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, $request->location);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HEADER, 0);

    // grab URL and pass it to the browser
    $img = curl_exec($ch);

    // close cURL resource, and free up system resources
    curl_close($ch);

    return $img;
我想返回该blob并将其附加到客户端/javascript上的FileReader对象。

只要使用就会得到图像的原始内容。无需执行另一个curl请求

return file_get_contents($request->location);
您是否使用过“图像blob”javascript库?也许可以试试。 请查收

或者您也可以尝试使用“JavaScript画布到Blob”,以查看更多详细信息


我曾经尝试使用javascript将图像url转换为base64,如果您感兴趣,我可以共享代码。

为什么要加载两次图像?到底是什么问题?你有错误吗?Blob的构造函数很简单,-那么你到底有什么问题?位置可以是pdf,也可以,因为我想用javascript将Blob附加到我的Filereader objectYes中,
file\u get\u contents
将加载任何文件,无论其类型如何。您有没有示例将其放入FileReader图像对象中?目前它看起来是这样的:
array(5){[“type”]=>string(10)“image/jpeg”[“file”]=>string(346734)“Iÿ216;ÿCÿQ°”IÿnÿJÎ9.JÎJÎIāYÔeÿfÿQ°”IÿuāYÿfÿnăd+