Domanda

I'm developing a database in Postgresql, accessed via browser (php/javascript) in Firefox/Ubuntu. It runs locally in the client machine, with database also local. Some tables have a "link" column, where the user stores the path to the file for that record (a report, a photo, a map, or even a whole folder). Right now I'm asking the client to copy the resource in Nautilus and paste it in the field of choice. This pastes the full path of the file, which is then stored in the database. So far, so good.

What I want now is to show a thumbnail of the files when the user asks to see what is on that table. I know javascript can't have access to the user disk's contents for security reasons. This site shows how to do something similar in HTML5, but it doesn't seem to have the full path for the file. Somewhere else I've read Flash could do it (somewhere else I read it couldn't), but Flash is not free. Any free technology to make this work? Thanks in advance.

È stato utile?

Soluzione

There are several ways of going about this. One option would be for the server to stream the images from the path in the database to the browser, for example if using PHP this would look like:

    $size = getimagesize($fname);
    // Now that you know the mime type, include it in the header.
    header('Content-type: '.$size['mime']);
    // Read the image and send it directly to the output.
    readfile($fname);

There are equivalent methods in any other server side scripting language.

Specifically, here's a tested sample code that does this. On the server side:

<?php
$param = $_GET["image"];
$fname = "/Users/myuser/images/$param"; // replace with your path
$size = getimagesize($fname);
header('Content-type: '.$size['mime']);
readfile($fname);
?>

On the client side

<html>
<head></head>
<body>
<img src="http://127.0.0.1/img.php?image=test1.png" />
<img src="http://127.0.0.1/img.php?image=test2.png" />
</body>
</html>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top