hello guys how are you i wrote this code but i have an proplem i can not verify if there is no file uploaded when anyone hit submit and i can not specific the allowed extinsion for example "jpg" how can i do this in "foreach", i can do this when i upload just one image but this code for multi upload and if have you noticed i have used array in the form.

<?php 

mysql_connect('localhost','root','root')or die (mysql_error());
mysql_select_db('storeimage');

?>


<?

if ($_POST['submit'] ){

$file=$_FILES['file'];
$name=$_FILES['file']['name'];
$tmp_name=$_FILES['file']['tmp_name'];

foreach($name as $key=>$value){

$name_file=$name[$key];
$tmp_file=$tmp_name[$key];
$imgpath = rand().'.jpeg'; 
move_uploaded_file($tmp_file,'images/'.$imgpath);


$insert=mysql_query("insert into  imagelocation values('','images/$imgpath')")or die (mysql_error());
$id=mysql_insert_id();
$select=mysql_query("select * from  imagelocation where id='$id' ");

while ($row=mysql_fetch_object($select)){
echo "<center><img src='$row->images'/></center><br/>";
}

}
}




?>





<form action='' method='post' enctype='multipart/form-data'>
<input type='file' name='file[]' multiple />
<input type='submit' name='submit'/>

</form>

Recommended Answers

All 4 Replies

if ($_FILES)
{
$temp_file = $_FILES['ufile']['tmp_name'];
 $upload_dir = "uploads";
$name = $_FILES['ufile']['name'];
switch($_FILES['ufile']['type'])
{
case 'image/jpeg': $ext = 'jpg'; break;
case 'image/gif': $ext = 'gif'; break;
case 'image/png': $ext = 'png'; break;
case 'image/tiff': $ext = 'tif'; break;
default: $ext = ''; break;
}
if ($ext)
{
$n = "$pic_name.$ext";
move_uploaded_file($temp_file, $upload_dir."/". $n);
echo "Uploaded image <img src='uploads/$pic_name.$ext'/> as '$n':<br />";


}
else echo "'$name' is not an accepted image file";
}
else echo "No image has been uploaded";


?>


I would recommed you try the above, as it tells wether a file is uploaded or not, or you could single out that fucntion and integrate it in your code. 

the proplem is i am newbie in php and i can not understand every things you write how it will be with my code and the code you have whrote is for upload one image not multi upload

please help me

Would it not make more sense to get a single upload functioning first, then you can modify the coding for multi upload

tahnk you guys propblem has been solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.