strange results in mysql with readdir.php

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

 



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");
?>

-- 
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