Re: strange results in mysql with readdir.php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Alessandro,

i think the sql insert statement should be:

insert into images(sixfourdata) values ('$encoded');

Rui Cunha

Alessandro Folghera writes:

Anybody has an idea about what happened to me ?

The following script should just charge in a mysql db the images located in
a directory. Unfortunately everytime I call "readdir.php" (never mind if
there are or not new images) mysql is charging 2 or 6 copies of the same
last image uploaded into the directory. Anybody may explain to me where I'm
failing?
Thanks for all the phpers!
Alessandro


<?
$dbcnx = mysql_connect("localhost", "root", "password"); mysql_select_db("news");


if (!$dbcnx) { echo( "<p>connection to database server failed!</p>");
exit();
}


if (! @mysql_select_db("news") )
{ echo( "<p>Image Database Not Available!</p >" ); exit(); }


$path = "./";
$dir_handle = @opendir($path) or die("Unable to open directory $path");


while ($file = readdir($dir_handle)) {
$filetyp = substr($file, -3);
if ($filetyp == 'gif' OR $filetyp == 'jpg') {
$handle = fopen($path . "/" . $file,'r');
$file_content = fread($handle,filesize($path . "/" . $file));
fclose($handle);


$encoded = chunk_split(base64_encode($file_content)); $sql = "INSERT INTO images SET sixfourdata='$encoded'";

@mysql_query($sql);
}
}
closedir($dir_handle);
echo("complete");
?>





*************************************
* Rui Pedro Cunha *
* Dpto. de Ciências e Tecnologias *
* Universidade Autónoma de Lisboa *
* Rua de Santa Marta, 56, *
* 1169-023 Lisboa *
* Telefone (+351) 21 317 76 35/49 *
* Fax (+351) 21 353 37 02 *
* Url : http://www.ual.pt/dct/ *
* E-mail: rui.cunha@xxxxxx *
*************************************


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux