# Record covers

  • Every record has a cover image that is stored locally in the /storage/covers directory
  • As you may have noticed, there is no cover column in the records table
  • The name of the image refers to the record's mb_id column
    E.g. if the mb_id value is f0a4ed57-10e0-4c37-81b4-36311dc7d4b6, the cover image must be f0a4ed57-10e0-4c37-81b4-36311dc7d4b6.jpg
  • Later on in the course, we discuss some scripts to upload, replace and delete cover images
  • To start using the covers, we prepared a small script to download a zip file containing all the covers and store them locally in the right folder
  • If you followed all the instructions when starting up our project, the symlink should already be created
  • If not, you can create it by running the following command in your terminal: php artisan storage:link

link already exists

  • If you execute the php artisan storage:link more than once, you get the following error: symlink error
  • You can ignore this error, as the link was already created during the initial startup of the project

# Download the covers

REMARKS

  • The script we prepared is written in "pure PHP" and does not use the Laravel framework, therefore we will not discuss this code in detail
  • Later on, you can re-run this script every time you need to reset to the default covers
  • Create a new file download_covers.php inside the public directory
  • Copy the following code into public/download_covers.php
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0">
    <title>Download covers</title>
    <script src="https://cdn.tailwindcss.com?plugins=typography"></script>
</head>
<body class="p-4 bg-green-200">
    <h1 class="text-2xl font-bold mb-2">Download covers</h1>
    <div class="max-w-3xl bg-white/75 border rounded-md shadow-xl p-4">
        <?php
            $download_url = "https://pverhaert.sinners.be/covers_vinylshop.zip";
            $download_to = "storage/covers.zip";
        
            $script = basename($_SERVER['PHP_SELF']);
            file_put_contents($download_to, fopen($download_url, 'r'));
            $path = pathinfo(realpath($download_to), PATHINFO_DIRNAME);
            $zip = new ZipArchive;
            $res = $zip->open($download_to);
            if ($res === TRUE) {
                $zip->extractTo($path);
                $zip->close();
                echo "<p>The file <b>$download_url</b><br>was successfully extracted to <b>$path</b></p>";
                unlink($download_to);
            } else {
                echo "<p>Couldn't open <b>$download_to</b></p>";
            }
            echo '<p class="mt-6"><a href="/" class="px-6 py-2 bg-green-600 text-white rounded">BACK HOME</a></p>';
        ?>
    </div>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

covers folder not visible

  • It might be possible that the covers folder doesn't appear in PhpStorm.
  • Try to right-click the storage/app/public folder and choose Reload from Disk to force your working directory to refresh

WARNING

All PHP files you create directly in the public directory (like download_covers.php) are completely separated from Laravel and therefore you should not create a route in web.php either.

Last Updated: 10/3/2022, 4:05:59 PM