3
I’m using a Github (xkeshi/image-compressor) project that compresses images using Javascript. It generates a download of the compressed file with the following link for example blob:http://localhost/945f825f-054a-4170-9d79-ac1dba593d23
Note that the URL starts with blob:
How to upload PHP from file to server, since apparently the file is local?
Dice:
Github project that originated question: https://github.com/xkeshi/image-compressor
What I’ve already tried
<?php
//Arquivo que desejo fazer upload blob:http://localhost/945f825f-054a-4170-9d79-ac1dba593d23
$url = 'blob:http://localhost/945f825f-054a-4170-9d79-ac1dba593d23';
$img = '/p/a.jpg';
file_put_contents($img, file_get_contents($url));
?>
Error showing
Warning: file_get_contents(blob:http://localhost/945f825f-054a-4170-9d79-ac1dba593d23): failed to open stream: Invalid argument in C: xampp htdocs 1 a b Docs p.php on line 5
Warning: file_put_contents(/p/a.jpg): failed to open stream: No such file or directory in C: xampp htdocs 1 a b Docs p.php on line 5
your problem is in the image path you provide as parameter
– 13dev
Consider adding the snippet of code you are using/instantiating the library. It’s hard to imagine how you got one objectURL once the library only returns
File
orBlob
– Lauro Moraes
Well, now I see where you got this objectURL...you took it off the page DEMO. Note that the repository is not public, the maintainer uses Vue and what it does is use the library to generate the
Blob()
and usesURL.createObjectURL()
to generate this link and assign to an element<a>
with the attributedownload
. You should consider the answer presented to you, it is the most recommended way to upload the object that the library returns to you.– Lauro Moraes