网站图片库

| 使用照片画廊时,是否有“标准”方式将照片存储在网络上? 将照片存储在mysql数据库中是不好的做法吗?我应该将照片存储在文件夹中,还是将链接存储在数据库中? 在谈论存储照片以在网站上使用时,什么是“良好做法”?     
已邀请:
        您可以使用不同的BLOB数据类型将照片存储在数据库中。如果照片数量过多或过大,则数据库开始受到性能影响,并且大小将急剧增加。本质上,如果您有100张10Mb的照片,那就是1,000Mb或大约将增长数据库的Gb大小。备份将永远执行,并且如果包含映像的表由于任何原因损坏,它将引起更多的头痛,而不是您想要处理的。 根据imoda的建议,我的建议是将它们存储在硬盘驱动器上,并在包含所有元数据的数据库中链接到它们,并提供指向文件位置的链接。最佳做法是将照片的文件名存储在数据库中,然后重命名该文件以使用主键的值作为文件名。例如,第5行与照片“ x”关联,其中x为文件名,将其存储在硬盘驱动器上,并将照片重命名为文件名5,然后当您访问文件进行下载之类的操作时,您将从数据库中第5行提取实际文件名并重命名下载之前。如果您碰巧上传两个或多个具有相同文件名的文件,则可以避免意外覆盖文件。     
        您有99%的时间不想将照片存储在MySQL数据库中。如果处理不当,将会占用大量资源。将照片存储在网站上的目录中,并将其路径存储在数据库中。     
        我建议使用Flickr添加/删除和重新排列图片。使用Flickr的优点是您不必编写任何复杂的代码或托管图片。您可以使用PHP和Flickr API使用您的个人资料ID检索图片。 1.使用Flickr创建一个应用 2.下载phpFlickr并将其放在服务器的根目录下 https://code.google.com/p/phpflickr/downloads/list 将此PHP代码添加到您的gallery.php文件中 这是带有分页的PHP Gallery的代码
<div class=\"portfolio-grid\">



    <?php

        $key = \"92d657c8dc79a29108d846a5fd121a29\";  //your API key
        $nsid = \"108400461@N02\";            //your NSID

        // get page number from the url - if there isn\'t one - we\'re on page 1
        $page = isset($_GET[\'page\']) ? $_GET[\'page\'] : 1;

        // inclue the core file
        require_once(\'phpFlickr/phpFlickr.php\');
        // Fire up the main phpFlickr class 
        $f = new phpFlickr($key);
        $f->enableCache(\"fs\", \"cache\");

        $photos = $f->people_getPublicPhotos($nsid, NULL, NULL, 20, $page);
        $pages = $photos[photos][pages]; // returns total number of pages
        $total = $photos[photos][total]; // returns how many photos there are in total
    ?>


    <!--END script Flick photos -->
    <div>
        <?php
            echo \'<div id=\"container\">\';
            // loop through each photo
             foreach ($photos[\'photos\'][\'photo\'] as $photo) {

            // print out a link to the photo page, attaching the id of the photo
                 echo \'<div class=\"item\" style=\"float:left;\">
                        <a class=\"swipebox-isotope\" href=\"\' . $f->buildPhotoURL($photo, \'Large\') . \'\" title=\"A.S.A.C - The African Student&apos;s Association of Concordia\"><img class=\"gallery-img\" src=\"\' . $f->buildPhotoURL($photo, \'medium\') . \'\" alt=\"\' . $photo[\'title\'] . \'\" title=\"\' . $photo[\'title\'] . \'\"/></a>
                      </div>\';

            // end loop
            }
            echo \'</div>\';
        ?>

    </div>

      </div>
  <h2 id=\"nav\">
    <?php
        // Some simple paging code to add Prev/Next to scroll through the thumbnails
        $back = $page - 1;
        $next = $page + 1;
        // if it\'s not the first page
        if($page > 1) {
        echo \"<a href=\'?page=$back\'>&laquo; <strong>Prev</strong></a>\";
        }




        // if not last page
        if($page != $pages) {
        echo \"<a style=\'float:right\' href=\'?page=$next\'><strong>Next</strong> &raquo;</a>\";}
        // a quick bit of info about where we are in the gallery
        echo\"<h3 style=\'text-align:center;\'>Page $page of $pages <br/>$total photos</h3>\";

    ?>
</h2>
    

要回复问题请先登录注册