将图像保存到文件夹 | PHP

发布于 2024-09-15 21:02:43 字数 811 浏览 1 评论 0原文

我希望能够打开提供的 URL(通过表单完成),该 URL 允许服务器将文件保存到目录中,例如:

http://www.google.co.uk/intl/en_com/images/srpr/logo1w.png

我想将该徽标保存到此目录中:

img/logos/

然后将通过在 so 之前给它一个随机文件名将其添加到数据库中,例如,

827489734.png

现在将使用以下内容将其插入到数据库中:

img/logos/827489734.png

我不想为此使用 cURL,我喜欢使用 fopen、file_get_contents 等。 ..

干杯。

编辑

$logo = safeInput($_POST['logo']);

if(filter_var($avatar, FILTER_VALIDATE_URL))
{
    $get_logo = file_get_contents($logo);
    $logo_directory = 'img/logos/';

    $save_logo = file_put_contents($logo_directory, $logo);

    if($save_logo)
    {
        $logo_path = $logo_directory . $save_logo;

这段代码的一部分我需要帮助......

I want to be able to open the provided URL (which is done via a form) that is an URL that will allow the server to save the file into a directory, for example:

http://www.google.co.uk/intl/en_com/images/srpr/logo1w.png

I want to save that logo into this directory:

img/logos/

Then it will add it to the database by giving it a random file name before so, e.g.

827489734.png

It will now be inserted to the database with the following:

img/logos/827489734.png

I do not want to use cURL for this, I like to work with fopen, file_get_contents, etc...

Cheers.

EDIT

$logo = safeInput($_POST['logo']);

if(filter_var($avatar, FILTER_VALIDATE_URL))
{
    $get_logo = file_get_contents($logo);
    $logo_directory = 'img/logos/';

    $save_logo = file_put_contents($logo_directory, $logo);

    if($save_logo)
    {
        $logo_path = $logo_directory . $save_logo;

A part of this code I need helping...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独岁月 2024-09-22 21:02:43

在执行 file_put_contents() 时,您需要指定完整的文件名。纯粹的目录名称不会减少它。

You need to specify a full file name when doing a file_put_contents(). A pure directory name won't cut it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文