Horje
How to read a txt file from a zip remote URL

Here makes it simple.

How it will work?

  1. First, It will download the zip file to path
  2. Second, It will extract text file that you want to read to index.php
  3. Third, It will auto delete zip file which saved path,

How to read a text file inside zip file of a remote url using PHP

Follow the following codes.

Install Guide.

  1. Create a folder named path in your domain
  2. Change folder permission of folder: path
  3. Create a file named index.php in your domain
  4. Insert following code inside index.php
  5. Replace Line 3 and add your remote url.
  6. Replace Line 14 #wpforms-lite/readme.txt and add Your Zip File's txt destination.
  7. Save it and Run into Browser.

 

index.php
Example: PHP
<?php

$url = 'https://downloads.wordpress.org/plugin/wpforms-lite.1.9.2.1.zip';
$destination_dir = 'path/';
if (!is_dir($destination_dir)) {
    mkdir($destination_dir, 0777, true);
}
$local_zip_file = basename(parse_url($url, PHP_URL_PATH)); // Will return only 'some_zip.zip'
if (!copy($url, $destination_dir . $local_zip_file)) {
    die('Failed to copy Zip from ' . $url . ' to ' . ($destination_dir . $local_zip_file));
}

// Change the txt file location which is inside of the zip file Example: #wpforms-lite/readme.txt
$result = file_get_contents('zip://path/'.$local_zip_file.'#wpforms-lite/readme.txt');

# Display txt file's texts
echo '<xmp>'.$result.'</xmp>';

$result = file_get_contents('zip://path/'.$local_zip_file.'#readme.txt');
echo $result;

$zip = new ZipArchive();
if ($zip->open($destination_dir . $local_zip_file)) {

    $zip->close();
    // Clear zip from local storage:
        unlink($destination_dir . $local_zip_file);
}
?>

Output should be:

How to read a text file inside zip file of a remote url using PHP




php zip

Related Articles
How to extract Domain Name from Full URL in PHP PHP Extract Tutorial
How to extract only name from domain in PHP PHP Extract Tutorial
How to extract All url from a single page by PHP PHP Extract Tutorial
How to get first Five Line from CSV File PHP Extract Tutorial
How to get first 100 records from a csv file in PHP PHP Extract Tutorial
How to get meta Tag PHP Extract Tutorial
How to get title description image and multiple images from URL PHP Extract Tutorial
How to read a txt file from a zip remote URL PHP Extract Tutorial
How to extract all url from a html single page in PHP PHP Extract Tutorial

Single Articles
How to read a text file inside zip file of a remote url using PHPPHP Extract Tutorial

Read Full:
PHP Extract Tutorial
Type:
Develop
Category:
Web Tutorial
Sub Category:
PHP Extract Tutorial
Uploaded:
3 weeks ago
Uploaded by:
Admin
Views:
77



Share on: