Hướng dẫn php ziparchive add file from url - php ziparchive thêm tệp từ url

Tôi đã tự hỏi liệu những điều sau đây có thể làm được không và với hy vọng ai đó có khả năng giúp tôi.

Tôi muốn tạo một tính năng 'tải xuống zip' nhưng khi các nhấp chuột riêng lẻ để tải xuống thì nút lấy hình ảnh từ miền bên ngoài của tôi và sau đó đóng gói chúng thành một zip và sau đó tải nó cho chúng.

Tôi đã kiểm tra cách làm điều này và tôi không thể tìm thấy bất kỳ cách nào tốt để lấy hình ảnh và buộc chúng vào một zip để tải xuống.

Tôi đã hy vọng ai đó có thể hỗ trợ

Hỏi ngày 18 tháng 12 năm 2012 lúc 9:38Dec 18, 2012 at 9:38

NGPlaygroundngplayglayngplayground

19.2K34 Huy hiệu vàng93 Huy hiệu bạc169 Huy hiệu đồng34 gold badges93 silver badges169 bronze badges

2

# define file array $files = array( '//www.google.com/images/logo.png', '//upload.wikimedia.org/wikipedia/commons/thumb/5/53/Wikipedia-logo-en-big.png/220px-Wikipedia-logo-en-big.png', ); # create new zip object $zip = new ZipArchive(); # create a temp file & open it $tmp_file = tempnam('.', ''); $zip->open($tmp_file, ZipArchive::CREATE); # loop through each file foreach ($files as $file) { # download file $download_file = file_get_contents($file); #add it to the zip $zip->addFromString(basename($file), $download_file); } # close zip $zip->close(); # send the file to the browser as a download header('Content-disposition: attachment; filename="my file.zip"'); header('Content-type: application/zip'); readfile($tmp_file); unlink($tmp_file);

Lưu ý: Giải pháp này giả định bạn đã bật allow_url_fopen. Nếu không, hãy nhìn vào sử dụng Curl để tải xuống tệp.

Đã trả lời ngày 18 tháng 12 năm 2012 lúc 9:53Dec 18, 2012 at 9:53

13

Tôi hy vọng tôi không hiểu sai.

//php.net/manual/en/book.zip.php

Tôi đã không thử điều này, nhưng có vẻ như những gì bạn đang tìm kiếm.

<?php $zip = new ZipArchive; if ($zip->open('my_archive.zip') === TRUE) { $zip->addFile($url, basename($url)); $zip->close(); echo 'ok'; } else { echo 'failed'; } ?>

Đã trả lời ngày 18 tháng 12 năm 2012 lúc 9:46Dec 18, 2012 at 9:46

Không thích thúNot Amused

9122 Huy hiệu vàng9 Huy hiệu bạc28 Huy hiệu đồng2 gold badges9 silver badges28 bronze badges

0

Thảo luận về các vấn đề mã hóa và tập lệnh liên quan đến PHP và MySQL.

Janmolendijkposts: 270Location: Hà Lan RotterdamPosts: 270Location: Holland Rotterdam

Thêm hình ảnh từ URL đến kho lưu trữ zip trong PHP

Xin chào Trưởng phòng Hy vọng bạn làm tốt?

Tôi có ở đây một mã, nó tạo ra một thiết bị lưu trữ zip + đặt một văn bản-tài liệu trong thiết bị lưu trữ zip, điều này hoạt động chính xác .... nhưng tôi muốn thêm một hình ảnh trong thiết bị phân tầng zip, tôi đã thử một số thứ nhưng không có gì đang làm việc
this works correctly.... But I would like to add a picture in the zip-archive
I tried some things but nothing is working

Mã: Chọn tất cả

<?php $today = date("F j, Y, g:i a"); $files ='//145.53.93.209/Molendijk/add/load/pictures/'.$users["post_image"].''; $zip = new ZipArchive; if ($zip->open(''.$users["post_user_name"].'/Backup/'.$users["title"].'.zip', ZipArchive::CREATE) == TRUE){ // Add files to the zip file $zip->addFile(''.$users["post_user_name"].'/Backup/'.$users["title"].''); $zip->addFile(''.$users["post_user_name"].'/Backup/'.$users["title"].'/$files'); // Add File3.txt file to zip and rename it to File5.txt // Add a file newFile.txt file to zip by adding specified text in newFile.txt $zip->addFromString('@Molendijk-'.$users["title"].'.txt', 'Welcome to @Molendijk I just extracted your '.$users["title"].' on '.date("F j, Y, g:i a").' your located with ip: '.$_SERVER["REMOTE_ADDR"].' '.$users["post_text"].' '); // All files are added, so close the zip file. $zip->close(); } ?>

Tôi cố gắng với $ Files để thêm hình ảnh vào thiết bị lưu trữ zip

Mã: Chọn tất cả

$files ='//145.53.93.209/Molendijk/add/load/pictures/'.$users["post_image"].'';

Mã: Chọn tất cả

$zip->addFile(''.$users["post_user_name"].'/Backup/'.$users["title"].'/$files');

Tôi cố gắng với $ Files để thêm hình ảnh vào thiết bị lưu trữ zip

Hãy giúp tôi ra.... Posts: 805

Quản trị viên: 805
I'm fine.

Xin chào tôi khỏe.

Mã: Chọn tất cả

$url ='//domain.com/address/file_name'; $zip = new ZipArchive(); if($zip->open('dir/file.zip', ZipArchive::CREATE) == TRUE){ #add file from $url into the zip $get_file = file_get_contents($url); $zip->addFromString(basename($url), $get_file); $zip->close(); }

Tôi cố gắng với $ Files để thêm hình ảnh vào thiết bị lưu trữ zip

Mã: Chọn tất cả

<?php $today = date("F j, Y, g:i a"); $url ='//145.53.93.209/Molendijk/add/load/pictures/'.$users["post_image"].''; $zip = new ZipArchive; if($zip->open(''.$users["post_user_name"].'/Backup/'.$users["title"].'.zip', ZipArchive::CREATE) == TRUE){ #add file from $url itto the zip $get_file = file_get_contents($url); $zip->addFromString(basename($url), $get_file); // Add a file newFile.txt file to zip by adding specified text in newFile.txt $zip->addFromString('@Molendijk-'.$users["title"].'.txt', 'Welcome to @Molendijk I just extracted your '.$users["title"].' on '.$today.' your located with ip: '.$_SERVER["REMOTE_ADDR"].' '.$users['post_text']); // All files are added, so close the zip file. $zip->close(); } ?>

Tôi cố gắng với $ Files để thêm hình ảnh vào thiết bị lưu trữ zip Posts: 270

Hãy giúp tôi ra....
comments + pictures are now archived in .zip-map.

Quản trị viên: 805

Cảm ơn một lần nữa

Chủ đề tương tự

  • Thêm vị trí cho hình ảnh trong JS JavaScript - JQuery - AjaxJavaScript - jQuery - Ajax

    Bài viết đầu tiên

    Các khóa học Plessantweb, tôi có một kịch bản nhỏ mà hiển thị trực tiếp trong một tài liệu từ một cơ sở.
    what shows directly in a document from a base-url.

    Bây giờ tôi muốn quảng cáo vị trí thủ công ...

    Bài cuối cùng

    Marplo cảm ơn rất nhiều, tôi không biết phải làm gì ....

    Câu hỏi khác đối tác của bạn từ các khóa học là làm thế nào? Tôi nghĩ rằng tôi đã không nhìn thấy anh ấy vì ...
    from Coursesweb doing ?
    I think I did not see him for...

Chủ đề