开发者

Image storage on mysql or server for content management

开发者 https://www.devze.com 2023-03-14 05:16 出处:网络
I have been using a php sql system to manage images on my website. I can easily upload new images, edit existing ones and delete them from mysql using php.

I have been using a php sql system to manage images on my website. I can easily upload new images, edit existing ones and delete them from mysql using php. However, I was finding it extremely difficult to populate flash galleries driven from xml as I couldn't transfer the BLOB data to xml correctly.

Consequently, I have setup an upload script that inserts the 开发者_如何学Pythonimage into an "images" folder on my server, and adds id, image path, title and gallery in a mysql table. It is all working correctly, but now when it comes to editing and deleting the images I am stuck!

Would you recommend I stick with the first methodology (storing images as BLOBs) and try to figure out how to populate slideshows with this data, OR stick with the second approach and seek advice on how to edit and delete the images using php?

Thanks in advance for the advice, getting more and more stressed trying to get this sorted now! All I need is a simple image management tool that can also populate slideshows....!

JD


Your new approach is preferable in my opinion, and I personally know of no projects in my working environment that use blobs to store images (and we have some amazing web2print solutions).

I suggest you look for some tutorials about manipulating files in Google. It's easy!

Below is an tiny example of how you could do it. This includes alot of guessing though - as I do not know your setup / code / security requirements. I suggest you just get started and post any further problems you might encounter.

if ($_SERVER['REQUEST_METHOD'] == "POST") {

    // Get File info of file that has to be deleted.
    $iFileId = $_POST['fileToDelete'];
    $sSelectQuery = "SELECT filePath FROM files WHERE fileId = %d";
    $sSelectQuery = sprintf($sSelectQuery, (int)$iFileId);
    $rResult = $oDatabase->query($sSelectQuery);
    $aFileInfo = $oDatabase->fetch($rResult);

    // Remove file from disk.
    unlink($aFileInfo['pathtoFile']);

    // Remove file from database.
    $sDeleteQuery = "DELETE FROM files WHERE fileId = %d";
    $sDeleteQuery = sprintf($sSelectQuery, $iFileId);
    $oDatabase->query($sDeleteQuery);

    // Done
} 


I personally prefer storing the image on the HD. This allows for easy scalability (you can move off your images to NFS or CDN or whatever)

If you have the image name stored in the DB, then picking up and editing the file from the HD shouldn't be a big deal and you can always use unlink() to delete the file, not as easy as deleting the record from the DB but i think the effort is worth it in the long term.

Besides i believe when you store images on the HD, you are taking a substantial load off of your DB server. So i think you stick with the new approach and iron out the issues you are having.

Just my 2 cents.

0

精彩评论

暂无评论...
验证码 换一张
取 消