Pokusavam da napravim formu za upload vise fotografija odjednom, ali mmi ne uspeva
Ovo je moj index.php
<body>
<form enctype="multipart/form-data" action="../zavrsni9.1/add.php" method="POST">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name = "email"><br>
Phone: <input type="text" name = "phone"><br>
Photo: <input type="file" name="photo1"><br>
Photo: <input type="file" name="photo2"><br>
Photo: <input type="file" name="photo3"><br>
Photo: <input type="file" name="photo4"><br>
<input type="submit" value="Add">
</form>
</body>
A ovo je moj add.php
<body>
<?php
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo[ ]']['name']);
//This gets all the other information from the form
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$filename=($_FILES['photo[ ]']['name']);
// Connects to your Database
mysql_connect("localhost", "root", "123") or die(mysql_error()) ;
mysql_select_db("employees") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$filename')") ;
//This function separates the extension from the rest of the file name and returns it
function findExtension ($filename)
{
$filename = strtolower($filename) ;
$exts = explode(".", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
//This applies the function to our file
$ext = findExtension ($_FILES['photo[ ]']['name']) ;
//This line assigns a random number to a variable. You could also use a timestamp here if you prefer.
$ran = rand () ;
//This takes the random number (or timestamp) you generated and adds a . on the end, so it is ready of the file extension to be appended.
$ran2 = $ran.".";
//This assigns the subdirectory you want to save into... make sure it exists!
$target = "images/";
//This combines the directory, the random file name, and the extension
$target = $target . $ran2.$ext;
if(move_uploaded_file($_FILES['photo[ ]']['tmp_name'], $target))
{
echo "The file has been uploaded as ".$ran2.$ext;
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
?>
<?
$uploaddir = "images/";
if(isset($_FILES) && is_array($_FILES) && count($_FILES)>0){
foreach($_FILES as $file) {
echo "Attempting to Upload<br>";
if(move_uploaded_file($file["tmp_name"],$uploaddir.$file["name"])){
echo "Uploaded File";
if ($file['type']!="image/jpeg"){
echo "Non Image";
unlink($uploaddir.$file["name"]);
}
else{
echo "Image file";
}
}
else{
echo "Could not Upload File<br>";
}
}
}
else{
echo "Error";
}
?>
</body>
Prijavljuje mi gresku Undefined index: photo[ ]
Svaka pomoc bi mi bila dobrodosla....
|