altctrldel
Technical User
- Jul 26, 2003
- 30
heres the code I followed from spoono.com in uploading all image files in a certain directory into rows in mysql:
I like the idea of converting the image into an encrypted long text. That way the image is stored directly into the database in plain text.
What I can't figure out is how to modify the script in order to:
use a file browser instead of having it find all the gifs and jpegs in a defined directory.
my sad attempt:
I get errors in fopen, fclose....
thanks in advance.
Code:
while ($file = readdir($dir_handle)) {
$filetyp = substr($file, -3);
if ($filetyp == 'gif' OR $filetyp == 'jpg') {
$handle = fopen($file,'r');
$file_content = fread($handle,filesize($file));
fclose($handle);
$encoded = chunk_split(base64_encode($file_content));
echo $encoded;
$sql = "INSERT INTO images SET imagefield='$encoded'";
mysql_query($sql);
}
}
closedir($dir_handle);
echo("complete");
mysql_close($dbcnx);
?>
I like the idea of converting the image into an encrypted long text. That way the image is stored directly into the database in plain text.
What I can't figure out is how to modify the script in order to:
use a file browser instead of having it find all the gifs and jpegs in a defined directory.
my sad attempt:
Code:
<input type=\"file\" name=\"image\" size=\"40\" maxlength=\"1024\" />
[b]$image[/b] = $_POST['image'];
$filetyp = substr([b]$image[/b], -3);
if ($filetyp == 'gif' OR $filetyp == 'jpg') {
$handle = fopen($file,'r');
$file_content = fread($handle,filesize([b]$image[/b]));
fclose($handle);
$encoded = chunk_split(base64_encode($file_content));
echo $encoded; // to see if it works...
}
I get errors in fopen, fclose....
thanks in advance.