可能重复:
使用php从php url保存图像
我想拥有以下PHP代码.
假设我有一个图片网址,例如http://www.google.co.in/intl/en_com/images/srpr/logo1w.png
如果我运行一个脚本,该图像将被复制并放在我的服务器上具有777权限的文件夹中.
可能吗?如果是的话,请你指点一下吗?
谢谢,
伊恩
可能重复:
从PHP URL保存图像
我有一个图像作为来自第三方网站拇指网站的网址链接(IE http://images.websnapr.com/?size=size&key=Y64Q44QLt12u&url=http://google.com)我想要做的是运行一个脚本,它使用php获取图像并将其保存在我的服务器上的目录中.这该怎么做?我会使用文件写入吗?
我有以下代码:
$file = 'http://3.bp.blogspot.com/-AGI4aY2SFaE/Tg8yoG3ijTI/AAAAAAAAA5k/nJB-mDhc8Ds/s400/rizal001.jpg';
$newfile = '/img/submitted/yoyo.jpg';
if ( copy($file, $newfile) ) {
echo "Copy success!";
}else{
echo "Copy failed.";
}
Run Code Online (Sandbox Code Playgroud)
它总是输出"复制失败"
copy(/img/submitted/yoyo.jpg) [function.copy]: failed to open stream: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我的目录设置为777.
有任何想法吗?谢谢!
我正在使用php的file_get_contents()函数来执行HTTP请求.为了节省带宽,我决定使用添加"Accept-Encoding: gzip"标头stream_context_create().
显然,file_get_contents()输出一个gzip编码的字符串,所以我gzuncompress()用来解码编码的字符串,但我得到一个错误,数据作为参数传递.
[...] PHP Warning: gzuncompress(): data error in /path/to/phpscript.php on line 26
Run Code Online (Sandbox Code Playgroud)
我知道还有另一个功能可以解压缩gzip压缩数据gzdecode()但它不包含在我的PHP版本中(可能只在SVN上可用).
我知道cUrl动态解码gzip流(没有任何问题),但有人建议我使用file_get_contents()而不是cUrl.
你知道在PHP中解压缩gzip压缩数据的任何其他方法或为什么gzuncompress()输出警告?荒谬的是gzuncompress()不能按预期工作.
注意:问题当然是关于PHP:HTTP请求是针对Tumblr API提供的,它提供了良好编码的响应.
如何使用php从URL下载图像(例如:https://www.google.com/images/srpr/logo3w.png)然后保存?这是我到目前为止提出的,它在'file_put_contents'函数中给出了一个错误.
<form method="post" action="">
<textarea name="text" cols="60" rows="10">
</textarea><br/>
<input type="submit" class="button" value="submit" />
</form>
<?php
$img = "no image";
if (isset($_POST['text']))
{
$content = file_get_contents($_POST['text']);
$img_path = '/images/';
file_put_contents($img_path, $content);
$img = "<img src=\"".$img_path."\"/>";
}
echo $img;
?>
Run Code Online (Sandbox Code Playgroud)
它给了我错误:
[function.file-put-contents]: failed to open stream: No such file or directory in C:\wamp\www\img.php
该/images/目录位于php文件的同一目录中,并且是可写的.
在我正在进行的项目的后期阶段,我遇到了一个严重的问题:
我编写了一个PHP函数,使用户可以通过单击其链接在硬盘上自动下载图像.但这很容易,因为图像上传到网站服务器,我知道它是完整的服务器地址.例如:"home/clients/websites/w_apo/public_html/wp-content/uploads/image.jpg"
但是现在客户希望能够从他自己的地址粘贴图像URL,http://www.something.com/image.jpg并且仍然能够通过单击前端上的链接自动下载该图像.
我在这个编程领域有点新意,所以我真的需要你的帮助.任何链接,建议,资源都是最受欢迎的.
谢谢!
这是我目前的下载功能:
download_file($_GET['file']);
/******************************************************************/
function download_file( $fullPath ){
// Must be fresh start
if( headers_sent() )
die('Headers Sent');
// Required for some browsers
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
// File Exists?
if( file_exists($fullPath) ){
// Parse Info / Get Extension
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
// Determine Content Type
switch ($ext) {
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; …Run Code Online (Sandbox Code Playgroud) 可能重复:
使用php从php url保存图像
我如何使用PHP从另一个域(不在我的域/服务器上)保存/获取图像并将其保存在我的站点的目录中.
例如,图像的URL将是:
http://anothersite/images/goods.jpg
Run Code Online (Sandbox Code Playgroud)
我如何使用PHP来获取"good.jpg",并将其保存在我的目录中 www.mysite.com/directory/
我希望有人可以指导我.谢谢!
我想知道如何通过URL而非输入将文件上传到Firebase的存储中(例如)。我正在从网站上抓取图像并检索其URL。我想通过一个foreach语句传递这些URL,然后将它们上传到Firebase的存储中。现在,我有使用以下代码的firebase upload-via-input输入:
var auth = firebase.auth();
var storageRef = firebase.storage().ref();
function handleFileSelect(evt) {
evt.stopPropagation();
evt.preventDefault();
var file = evt.target.files[0];
var metadata = {
'contentType': file.type
};
// Push to child path.
var uploadTask = storageRef.child('images/' + file.name).put(file, metadata);
// Listen for errors and completion of the upload.
// [START oncomplete]
uploadTask.on('state_changed', null, function(error) {
// [START onfailure]
console.error('Upload failed:', error);
// [END onfailure]
}, function() {
console.log('Uploaded',uploadTask.snapshot.totalBytes,'bytes.');
console.log(uploadTask.snapshot.metadata);
var url = uploadTask.snapshot.metadata.downloadURLs[0];
console.log('File available at', url);
// [START_EXCLUDE]
document.getElementById('linkbox').innerHTML = …Run Code Online (Sandbox Code Playgroud) 菜鸟网络开发人员在这里。
我正在尝试通过单击从 url 下载图像。但是当我使用图像 url 作为我的 href 时,它只是重定向到该 url 而不是下载。当然,我正在使用下载属性。我尝试了自己的代码,也尝试了其他人的多个代码块。但他们都只是重定向。我正在使用谷歌浏览器。
我的代码:
<a href = "https://autoooo.nl/wp-content/uploads/2018/12/F5144B9C-2B27-4070-828E-2361EBD702EF-400x400.jpeg" download="car" id="downloadQRCodeButtonHref">
<p>download</p>
</a>
Run Code Online (Sandbox Code Playgroud)
我从别人那里使用的代码1(接受的答案):
<a download="custom-filename.jpg" href="/path/to/image" title="ImageName">
<img alt="ImageName" src="/path/to/image">
</a>
Run Code Online (Sandbox Code Playgroud)
我从别人那里使用的代码2:
<p> Click the image ! You can download! </p>
<?php
$image = basename("http://localhost/sc/img/logo.png"); // you can here put the image path dynamically
//echo $image;
?>
<a download="<?php echo $image; ?>" href="http://localhost/sc/img/logo.png" title="Logo title">
<img alt="logo" src="http://localhost/sc/img/logo.png">
</a>
Run Code Online (Sandbox Code Playgroud)
一些帮助将不胜感激。我可能只是一个大笨蛋,忽略了一些非常明显的东西。
我制作的剧本是.
<?php
$source_file = 'http://www.domain.tld/directory/img.png';
$dest_file = '/home/user/public_html/directory/directory/img.png';
copy($source_file, $dest_file);
?>
Run Code Online (Sandbox Code Playgroud)
每次脚本运行时,我都需要删除该图像并重新上载.我要么想要它是img1.png,img2.png,img3.png等等.或者img(日期,时间).png,img(日期,时间).png等.这是可能的,如果是的话,如何我这样做吗?