I try to combined html and php for multiple file upload on my website. But the result show some code on screen. It happened when I use .html , but it disappeared when I use .php .. what should I do to use .html but the error doesn't happen?
<!DOCTYPE html>
<html>
<body>
<?php
if(isset($_POST['submit'])){
if(count($_FILES['upload']['name']) > 0){
for($i=0; $i <count($_FILES['upload']['name']); $i++) {
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
if($tmpFilePath != ""){
//save the filename
$shortname = $_FILES['upload']['name'][$i];
//save the url and the file
$filePath = "upload/" . date('d-m-Y-H-i-s').'-'.$_FILES['upload']['name'][$i];
if(move_uploaded_file($tmpFilePath, $filePath)) {
$files[] = $shortname;
}
}
}
}
echo "<h1>Uploaded:</h1>";
if(is_array($files)){
echo "<ul>";
foreach($files as $file){
echo "<li>$file</li>";
}
echo "</ul>";
}
}
?>
<form action="" enctype="multipart/form-data" method="post">
<div>
<label for='upload'>Add Attachments:</label>
<input id='upload' name="upload[]" type="file" multiple="multiple" />
</div>
<p><input type="submit" name="submit" value="Submit"></p>
</form>
</body>
</html>
What should I edit? Thanks.
</div>
first: Please run your script on server side using wamp or similar servers
second: I guess the following edit t your code
count($_FILES) not count($_FILES['file']['name'])
third: also, have to check the files are empty or not for the first time