1024programmer News Dev Note: Saving images from URLs without forms (Symfony3)

Dev Note: Saving images from URLs without forms (Symfony3)

Introduction: This article is compiled by the editor of Programming Notes# for you. It mainly introduces the knowledge related to saving images from URLs without forms (Symfony 3). I hope it has certain reference value for you.

I want to save an image (from URL) and relocate it to another folder without creating a form to the controller. How can I realize this?

Download image in Controller -> relocate it to another folder -> save image name into my database (in existing table).

Answer

Your question is broad, you didn’t specify which Doctrine DBAL and ORM you’re using and what exactly your question is, so I’m assuming you do use them and you know how to control Inject the entity manager in the manager action.

First you have to download the image and save the image:

$cOntent= file_get_contents("http://example.com/image.jpg");
//Store in the filesystem.
$fp = fopen("/location/to/save/image.jpg", "w");
fwrite($fp, $content);
fclose( $fp);

Then save the path to the database:

$imageEntity->setPath('image.jpg');
$entityManager->flush($imageEntity);

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/dev-note-saving-images-from-urls-without-forms-symfony3/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索