Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
440 views
in Technique[技术] by (71.8m points)

php - Intervention Image: Save image directly from an url with original file name and ext?

How to get the filename, when taking image from a remote server? And how to save with original size and filename?

// Take remote image
$img = Image::make('http://image.info/demo.jpg');
// how to save in the img/original/demo.jpg
$img->save(????);

I use Intervention, (http://image.intervention.io/api/make) to build CakePHP 3 image Behavior, I want to provide an easy uploading from remote servers, and keep the original image as a source for future manipulation.

EDIT

I ask, is there the Intervention Image method that returns the name of the file, when taken from the remote server. I know php copy(), basename(), I can also use the CakePHP File utilities, but it gives me the duplicate request on remote file.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

response() does not return the original filename like Salines was requesting. This should work

$path = 'https://i.stack.imgur.com/koFpQ.png';
$filename = basename($path);

Image::make($path)->save(public_path('images/' . $filename));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...