gpt4 book ai didi

php - 上传文件到我的网站目录

转载 作者:搜寻专家 更新时间:2023-10-31 21:21:56 24 4
gpt4 key购买 nike

我正在尝试使用 URL 将文件 (png) 上传到我的 Web 目录:

$url = "http://api.qrserver.com/v1/create-qr-code/?data=hello_word&size=100x100";
$file = file_get_contents($url);
$fileName = "filename";
$dir = $this->get('kernel')->getRootDir() . '/../web/uploads/img';
$file->move( $dir , $fileName);

Warning: file_get_contents(http://api.qrserver.com/v1/create-qr-code/?data=hello_word&size=100x100): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

最佳答案

$fileName = "filename";
$dir = $this->get('kernel')->getRootDir() .
'/../web/uploads/img'.$fileName;
$ch = curl_init('http://api.qrserver.com/v1/create-qr-code/?
data=hello_word&size=100x100');
$fp = fopen($dir, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);

尝试类似的东西。如果这不起作用,我会考虑使用。 http://php.net/manual/en/function.file-put-contents.php

关于php - 上传文件到我的网站目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45670692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com