...

View Full Version : Multiple image upload script



levani
02-12-2010, 01:41 PM
Hello,

Looking for a simple php multiple upload script for images. Do you happen to have any?

Found this script via googe:


<?

while(list($key,$value) = each($_FILES['images']['name']))
{
if(!empty($value))
{
$filename = $value;
$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line

$add = "upimg/$filename";
//echo $_FILES['images']['type'][$key];
// echo "<br>";
copy($_FILES['images']['tmp_name'][$key], $add);
chmod("$add",0777);


}
}


?>

but it has one serious bug, it overwrites files with the same names... How can I fix that problem? Also I need to send the uploaded file path to the database...

Can anyone please help?

Thanks in advance

abduraooft
02-12-2010, 02:18 PM
Try
$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line

while(file_exists('upimg/'.$filename))
$filename=rand(1,9999).$filename;
$add = "upimg/$filename";

levani
02-12-2010, 02:44 PM
Thanks for help, works fine. And the last question, where should I add the mysql insert query to insert the file name into the database if the file is uploaded... How should I get the uploaded file name for this purpose?

abduraooft
02-12-2010, 02:51 PM
echo $filename;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum