Upload a Profile Image in PHP & MySQL: What am I doing wrong? - php

I wrote the code thrice before coming here. Each time I got the same problem: The profile image does not change from the default placeholder to the new uploaded image. Here is the index.php file:
<?php
session_start();
$conn = mysqli_connect("localhost", "root", "", "imgupload");
?>
<!DOCTYPE html><html><head></head><body>
<?php
$sql_user = "SELECT * FROM user";
$result = mysqli_query($conn, $sql_user);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$id = $row['id']; //gets the id of the user just selected from the database
$sql_img = "SELECT * FROM profileimg WHERE userid='$id'"; //check if we actually have a profile image uploaded from this user
$resultImg = mysqli_query($conn, $sql_img); //check what the status is of this user in the image table
while ($rowImg = mysqli_fetch_assoc($resultImg)) {
echo "<div class='user-container'>"; //check image status: uploaded or not uploaded
if ($rowImg['status'] == 0) {
echo "<img src='uploads/profile".$id.".jpg'>";
} else {
echo "<img src='uploads/profiledefault.jpg'>";
}
echo "<p>".$row['username']."</p>";
echo "</div>";
}
}
} else {
echo "There are no users yet!";
}
if (isset($_SESSION['id'])) {
if ($_SESSION['id'] == 1) {
echo "You are logged in as user #1";
}
echo "<form action='upload.php' method='POST' enctype='multipart/form-data'>
<input type='file' name='file'>
<button type='submit' name='submit'>UPLOAD</button>
</form>";
} else {
echo "You are not logged in!";
echo "<form action='signup.php' method='POST'>
<input type='text' name='first' placeholder='First name'>
<input type='text' name='last' placeholder='Last name'>
<input type='text' name='uid' placeholder='Username'>
<input type='password' name='pwd' placeholder='Password'>
<button type='submit' name='submitSignup'>Signup</button>
</form>";
}
?>
<p>Login as Admin</p><form action="login.php" method="POST"><button type="submit" name="submitLogin">Login</button></form><p>Logout</p>
<form action="logout.php" method="POST"><button type="submit" name="submitLogout">Logout</button></form></body></html>
And here is the upload.php file:
<?php
session_start();
$conn = mysqli_connect("localhost", "root", "", "imgupload");
$id = $_SESSION['id'];
if (isset($_POST['submit'])) {
$file = $_FILES['file'];
$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
$fileType = $file['type'];
$fileExt = explode('.', $fileName); //returns an array of data
$fileActualExt = strtolower(end($fileExt)); //returns the last item in the array then lowercases it
$allowed = array('jpg', 'jpeg', 'png', 'pdf');
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) {
if ($fileSize < 1000000) {
$fileNameNew = "profile".$id.".".$fileActualExt;
$fileDestination = 'uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
$sql = "UPDATE profileimg SET status=0 WHERE userid='$id';";
$result = mysqli_query($conn, $sql);
header("Location: index.php?uploadsuccess");
} else {
echo "Your file is too big!";
}
} else {
echo "There was an error uploading your file!";
}
} else {
echo "You cannot upload files of this type!";
}
}
I doubt there's anything wrong in the signup.php file. Why won't the profile image change when I upload?

I don't see you set $_SESSION ["id"] . I think $ _SESSION ["id"] duplicate and
$fileNameNew = "profile".$id.".".$fileActualExt;
$fileNameNew can be as "profile1.jpg", if profile1.jpg already exists then you cannot add file profile1.jpg to upload folder

Related

PHP / MySQL: Image successfully save to database but failed to display at web page

I have a very weird problem in my system. I already create a system to upload the image to the database and display it. The problem is, the image is successfully uploaded but, it will return the message "Failed to upload!". Then, the picture that had been uploaded does not display. Below is my code:
<body>
<div class="wrapperDiv">
<form action="" method="post" id="form" enctype="multipart/form-data">
Upload image :
<input type="file" name="uploadFile" value="" />
<input type="submit" name="submitBtn" value="Upload" />
</form>
<?php
$last_insert_id = null;
include('db2.php');
if(isset($_POST['submitBtn']) && !empty($_POST['submitBtn'])) {
if(isset($_FILES['uploadFile']['name']) && !empty($_FILES['uploadFile']['name'])) {
//Allowed file type
$allowed_extensions = array("jpg","jpeg","png","gif");
//File extension
$ext = strtolower(pathinfo($_FILES['uploadFile']['name'], PATHINFO_EXTENSION));
//Check extension
if(in_array($ext, $allowed_extensions)) {
//Convert image to base64
$encoded_image = base64_encode(file_get_contents($_FILES['uploadFile']['tmp_name']));
$encoded_image = $encoded_image;
$query = "INSERT INTO tbl_images SET encoded_image = '".$encoded_image."'";
$sql = $conn->prepare($query);
$sql -> execute();
//$results = $sql -> fetchAll(PDO::FETCH_OBJ);
echo "File name : " . $_FILES['uploadFile']['name'];
echo "<br>";
if($sql->rowCount() > 1 ) {
echo "Status : Uploaded";
$last_insert_id = $conn-> lastInsertId();
} else {
echo "Status : Failed to upload!";
}
} else {
echo "File not allowed";
}
}
if($last_insert_id) {
$query = "SELECT encoded_image FROM tbl_images WHERE id= ". $last_insert_id;
$sql = $conn->prepare($query);
$sql -> execute();
if($sql->rowCount($sql) == 1 ) {
//$row = mysqli_fetch_object($result);
while($row = $sql->fetch(PDO::FETCH_ASSOC)) {
echo "<br><br>";
echo '<img src="'.$row->encoded_image.'" width="250">';
}
}
}
}
?>
</div>
</body>
Can someone help me? Thanks!
you doing some thing wrong first you encoded the image when store in database so you must decode it again, and the src in tag get a url not image content just echo the content like this:
header('Content-type: image/jpeg');
echo base64_decode($row->encoded_image);
or
<img src="data:image/png;base64,'.$row->encoded_image.'" width="250">
but at all, store images in database is not a good option, your database become too heavy and can't respond fast and get too memory you can just store the image name in database and move the file form special place in your server the you can show like this.
echo '<img src="specialRoot/'.$row->image_name.'" width="250">';
Store images in folder..
I have created uploads folder in root, you can create folder at anywhere and write your path while fetching the image..
<body>
<div class="wrapperDiv">
<form action="" method="post" id="form" enctype="multipart/form-data">
Upload image :
<input type="file" name="uploadFile" value="" />
<input type="submit" name="submitBtn" value="Upload" />
</form>
<?php
$last_insert_id = null;
include('db2.php');
if(isset($_POST['submitBtn']) && !empty($_POST['submitBtn'])) {
if(isset($_FILES['uploadFile']['name']) && !empty($_FILES['uploadFile']['name'])) {
//Allowed file type
$allowed_extensions = array("jpg","jpeg","png","gif");
$name = $_FILES['uploadFile']['name'];
$target_dir = "uploads/"; //give path of your folder where images are stored.
$target_file = $target_dir . basename($_FILES["uploadFile"]["name"]);
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
//Check extension
if( in_array($imageFileType,$allowed_extensions) ){
//Convert image to base64
$image_base64 = base64_encode(file_get_contents($_FILES['uploadFile']['tmp_name']) );
$encoded_image = 'data:image/'.$imageFileType.';base64,'.$image_base64;
//$encoded_image = base64_encode($_FILES['uploadFile']['tmp_name']);
//$encoded_image = $encoded_image;
$query = "INSERT INTO tbl_images SET encoded_image = '".$encoded_image."'";
$sql = $conn->prepare($query);
$result = $sql -> execute();
move_uploaded_file($_FILES['uploadFile']['tmp_name'],$target_dir.$name);
echo "File name : " . $_FILES['uploadFile']['name'];
echo "<br>";
if($result == 1) {
echo "Status : Uploaded";
$last_insert_id = $conn->insert_id;
} else {
echo "Status : Failed to upload!";
}
} else {
echo "File not allowed";
}
}
if($last_insert_id) {
$query = "SELECT encoded_image FROM tbl_images WHERE id= ". $last_insert_id;
$result = $conn->query($query);
while($row = $result->fetch_assoc()){
echo '<img src="'.$row['encoded_image'].'" width="250">';
}
}
}
?>
</div>
</body>

Why does the submit button just reload my page instead of sending the information?

When I press the submit button the page reloads but doesn't send me to the "upload.inc.php" file. After clicking the submit button I just arrive at the index.php file without anything happend.
I copied the code and tried the html part in another file and there it worked. Therefore the mistake has to be somewhere in the rest of the index.php file. I added already echo's in the beginning of the "upload.inc.php" file and it didn't change a thing. Thus the error is somewhere in the index.php file but I don't find it. I appriciate your help! I searched for 4-5 hours and didn't find it.. .
Index.php (html part)
<form action="includes/upload.inc.php" method='post' enctype='multipart/form-data'>
<input type='file' name='file'>
<input type='hidden' name='userId' value="<?php echo $id; ?>" >
<button type='submit' name='submit'>UPLOAD</button>
</form>
Index.php (full file)
<?php
require "header.php";
require "includes/dbh.inc.php";
?>
<main>
<?php
if (isset($_GET['login'])) {
//Login Bereich der Hilfe suchenden
if ($_GET['login'] == "successHelpSeeker") {
echo "<p> Hello help seeker. </p>";
}
//Login Bereich der Helfenden
elseif ($_GET['login'] == "successHelper") {
echo "<p> Hello Helper.</p>";
}
//Login Bereich für beide gleich
//Profilbild
$id = $_SESSION['userId'];
$sqlImg = "SELECT * FROM profileimg WHERE userid='$id'";
$resultImg = mysqli_query($conn, $sqlImg);
$rowImg = mysqli_fetch_assoc($resultImg);
echo "<div>";
//existiert schon ein Profilbild? bei 0 ja bei 1 nein
if ($rowImg['status'] == 0) {
echo "<img src='uploads/profile".$id.".jpg'>";
} else{
echo "<img src='uploads/profiledefault.jpg'>";
}
echo "<p>".$row['userid']."</p>";
echo "</div>";
//enctype specifies how the form data should be encoded --> ?>
<form action="includes/upload.inc.php" method='enctype='multipart/form-data'>
<input type='file' name='file'>
<input type='hidden' name='userId' value="<?php echo $id; ?>" >
<button type='submit' name='submit'>UPLOAD</button>
</form>
<?php
}
if(isset($_SESSION['userId'])){
echo '<p>You are logged in!!</p>';
}
else{
echo '<p>You are logged out!</p>';
}
?>
</main>
normally it should send the choosen file to the upload.inc.php file but it just reloads the page without sending the information.
Thanks a lot for your help!
upload.inc.php :
<?php
session_start();
require 'dbh.inc.php';
$id = $_POST['userId'];
if (isset($_POST['submit'])) {
$file = $_FILES['file'];
$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
$fielType = $file['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png');
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) {
if ($fileSize < 10000000) {
$fileNameNew = "profile".$id.".".$fileActualExt;
$fileDestination = '../uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
$sql = "UPDATE profilimg SET status=0 WHERE userid= '$id';";
$result = mysqli_query($conn, $sql);
header("Location: ../index.php?uploadsuccess");
}
} else {
echo "Your file is too big. Please upload a file which isn't bigger than 10 mb.";
}
} else {
echo "There was an error uploading your file.";
}
} else {
echo "Please upload only jpg, jpeg, png or pdf files.";
}
The crazy thing is, I changed the "action" to a new file with barely something in it. Still the submit button doesn't send me to the new file and just reloads the page. Could it be a problem which has to do with the sessions I'm working with? :O
Look in your index.php page method='enctype='mltipart/form-data'
<form action="includes/upload.inc.php" method='enctype='multipart/form-data'>
<input type='file' name='file'>
<input type='hidden' name='userId' value="<?php echo $id; ?>" >
<button type='submit' name='submit'>UPLOAD</button>
</form>
<?php
}

ajax php sql without refreshing

I'm not familiar with ajax and I'm trying to submit a form using one PHP page and ajax so that after form is submitted/updated the page doesn't refresh completly. the php page is loaded on a div section of a parent page.
Can someone point me in the right direction how to submit the form without refreshing the entire page?
Below the code I have so far, and it is only all in one php file. Thank you
<?php
$servername = "data";
$username = "data";
$password = "data";
$database = "data";
$successAdd="";
$errorAdd="";
$connect = mysql_connect($servername, $username, $password) or die("Not Connected");
mysql_select_db($database) or die("not selected");
if (isset($_POST['Add'])) {
$venueName = $_POST['cname'];
$file = $_FILES['file'];
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$file_size = $file['size'];
$file_error = $file['error'];
$file_ext = explode('.', $file_name);
$file_ext = strtolower(end($file_ext));
$allowed = array('png');
if (in_array($file_ext, $allowed)) {
if ($file_error == 0) {
$file_name_new = $venueName . '.' . $file_ext;
$file_destination = 'images/category/' . $file_name_new;
if (move_uploaded_file($file_tmp, $file_destination)) {
$sql = "INSERT INTO `categorytable`(`category`) VALUES ('$venueName')";
$result = mysql_query($sql, $connect);
if ($result != 0) {
$successAdd = "Success fully done";
} else {
$errorAdd = "Not done ";
}
}
} else {
$errorAdd = "Something is wrong";
}
} else {
$errorAdd = "Only png file allowed";
}
}
if (isset($_POST['Update'])) {
$venueName = $_POST['cname'];
$file = $_FILES['file'];
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$file_size = $file['size'];
$file_error = $file['error'];
$file_ext = explode('.', $file_name);
$file_ext = strtolower(end($file_ext));
$allowed = array('png');
if (in_array($file_ext, $allowed)) {
if ($file_error == 0) {
$file_name_new = $venueName . '.' . $file_ext;
$file_destination = 'images/category/' . $file_name_new;
if (move_uploaded_file($file_tmp, $file_destination)) {
$successAdd = "Success fully done";
}else{
$errorAdd = "Not Updated";
}
} else {
$errorAdd = "Something is wrong";
}
} else {
$errorAdd = "Only png file allowed";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<h3 style="color: red"><?php echo $errorAdd; ?></h3>
<h3 style="color: green"><?php echo $successAdd; ?></h3>
<!--<div style="float: left;width: 50%">-->
<h1>Add Category</h1>
<form action="" method="POST" enctype="multipart/form-data" id="add-category" >
Category Name <input type="text" name="cname" value="" /><br/>
Category Image <input type="file" name="file" accept="image/x-png"/><br/>
<input type="submit" value="Add" name="Add"/>
</form>
<!--</div>-->
<!--<div style="float: left;width: 50%">-->
<h1>Update Category</h1>
<form action="addCategory.php" method="POST" enctype="multipart/form-data" >
Select Category<select name="cname">
<?php
$sql = "SELECT * FROM `categorytable`";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
?>
<option value="<?php echo $row[1]; ?>"><?php echo $row[1]; ?></option>
<?php } ?>
</select><br/>
Category Image <input type="file" name="file" accept="image/x-png"/><br/>
<input type="submit" value="Update" name="Update"/>
</form>
<!--</div>-->
<div style="width: 25%;margin: 20px auto;float: left">
<table border="1">
<tr>
<th>Category Name</th>
<th>Category Image</th>
</tr>
<?php
$sql = "SELECT * FROM `categorytable`";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td><?php echo $row[1]; ?></td>
<td>
<img src="images/category/<?php echo $row[1]; ?>.png" height="50"/>
</td>
</tr>
<?php
}
?>
</table>
</div>
</body>
First things first, swap to PDO, ASAP. This will save you TONS of time and can help with SQL execution time, when used correctly (You can find a quick PDO tutorial here). To answer question, I would recommend you start with importing the jQuery library. It allows near effortless manipulation of the DOM.
Then, just do something like
$('#your-form-id-here').submit(function(clickEvent){
$.ajax({
url: 'http://www.foo.com/',
data: $('#your-form-id-here').serialize(),
method: 'POST',
success: function(Response){
//If the request is successful, this code gets executed
},
error: function(){
//If the request failed, this code gets executed
}
});
return false; <----This prevents the page from refreshing
});
Now lets break it down a bit
data: $('#your-form-id-here).serialize() <-- This gets all of your form data ready
NOTE: There's way more to it than this. You'll need to do some server-side stuff to make this work right. For instance, if you want a JSON object back, you'll need to return it. In php, I like to do something like
if(My request succeeded){
echo(json_encode(array(
'status' => 'success',
'message' => 'Request description/whatever you want here'
)));
}

Errors when running php code to upload image to a given path

This is the php i've used for uploading an image (from W3schools):
<?php
$target_dir = "images/";
$target_file = $target_dir . basename("firstfood.jpg");
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST "submit")) {
$check = getimagesize($_FILES "firstfood.jpg");
if($check !== false) {
echo "File is an image - " . $check "mime" . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES "firstfood.jpg", $target_file)) {
echo "The file ". basename( $_FILES "firstfood.jpg"). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
When I add it to the mainphp file (see in the middle of below code), with the path substitutions,
<?php // sqltest.php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);
if (isset($_POST['delete']) && isset($_POST['isbn']))
{
$isbn = get_post($conn, 'isbn');
$query = "DELETE FROM classics WHERE isbn='$isbn'";
$result = $conn->query($query);
if (!$result) echo "DELETE failed: $query<br>" .
$conn->error . "<br><br>";
}
if (isset($_POST['author']) &&
isset($_POST['title']) &&
isset($_POST['category']) &&
isset($_POST['year']) &&
isset($_POST['isbn']) &&
isset($_POST['sleeve']))
{
$author = get_post($conn, 'author');
$title = get_post($conn, 'title');
$category = get_post($conn, 'category');
$year = get_post($conn, 'year');
$isbn = get_post($conn, 'isbn');
$sleeve = get_post($conn, 'sleeve');
$query = "INSERT INTO classics VALUES" .
"('$author', '$title', '$category', '$year', '$isbn', '$sleeve')";
$result = $conn->query($query);
if (!$result) echo "INSERT failed: $query<br>" .
$conn->error . "<br><br>";
}
echo <<<_END
<form enctype="multipart/form-data" action="sqltest.php" method="post"><pre>
Author <input type="text" name="author">
Title <input type="text" name="title">
Category <input type="text" name="category">
Year <input type="text" name="year">
ISBN <input type="text" name="isbn">
Sleeve <input type="file" name="sleeve">
<input type="submit" value="Upload Image">
<?php
$target_dir = "images/";
$target_file = $target_dir . basename("firstfood.jpg");
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST "submit")) {
$check = getimagesize($_FILES "firstfood.jpg");
if($check !== false) {
echo "File is an image - " . $check "mime" . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES "firstfood.jpg", $target_file)) {
echo "The file ". basename( $_FILES "firstfood.jpg"). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
<input type="submit" value="ADD RECORD">
</pre></form>
_END;
$query = "SELECT * FROM classics";
$result = $conn->query($query);
if (!$result) die ("Database access failed: " . $conn->error);
$rows = $result->num_rows;
for ($j = 0 ; $j < $rows ; ++$j)
{
$result->data_seek($j);
$row = $result->fetch_array(MYSQLI_NUM);
echo <<<_END
<pre>
<form enctype="multipart/form-data" action="sqltest.php" method="post">
Author <input type="text" name="author" value=$row[0]>
Title <input type="text" name="title" value=$row[1]>
Category <input type="text" name="category" value=$row[2]>
Year <input type="text" name="year" value=$row[3]>
ISBN <input type="text" name="isbn" value=$row[4]>
</pre>
<input type="hidden" name="delete" value="yes">
<input type="hidden" name="isbn" value="$row[4]">
<input type="submit" value="EDIT RECORD"></form>
<input type="submit" value="DELETE RECORD"></form>
_END;
}
$result->close();
$conn->close();
function get_post($conn, $var)
{
return $conn->real_escape_string($_POST[$var]);
}
?>
It throws out a whole bunch of errors (all of which relate to the section of code i pasted first - for uploading an image). Here are a few:
Notice: Undefined variable: target_dir
Notice: Undefined variable:imageFileType
Notice: Undefined variable: target_file
Would really appreciate guidance on this, as I'm just starting out and can get around this. thanks,
you won't get interpreted that <?php ?> inserted between <<<_END _END;
echo <<<_END
<form>
<?php $string = ''; echo $string ?>
</form>
_END;
this gonna be treated as
echo "<form><?php $string = ''; echo $string ?></form>";
so you see errors "undefined variable" because it's same as
echo "<form><?php ". $string ."= ''; echo ". $string ." ?></form>";
check the source code of generated page, you will get sure.
Try this instead, it's not ideal, but will work in every case ;)
<?php ob_start(); ?>
<form>
<?php $string = ''; echo $string ?>
</form>
<?= ob_get_clean() ?>
and btw you have 2x </form> there
<input type="submit" value="EDIT RECORD"></form>
<input type="submit" value="DELETE RECORD"></form>

Multiple File Upload PHP

I use the Following code to upload a single file .With This code I can Upload a single file to the database .I want to make multiple files uploaded by selecting multiple files in a single input type file.What Changes should i make in the code to make it upload multiple files?
<?PHP
INCLUDE ("DB_Config.php");
$id=$_POST['id'];
$fileTypes = array('txt','doc','docx','ppt','pptx','pdf');
$fileParts = pathinfo($_FILES['uploaded_file']['name']);
if(in_array($fileParts['extension'],$fileTypes))
{
$filename = $_FILES["uploaded_file"]["name"];
$location = "E:\\test_TrainingMaterial/";
$file_size = $_FILES["uploaded_file"]["size"];
$path = $location . basename( $_FILES['uploaded_file']['name']);
if(file_exists($path))
{
echo "File Already Exists.<br/>";
echo "Please Rename and Try Again";
}
else
{
if($file_size < 209715200)
{
$move = move_uploaded_file( $_FILES["uploaded_file"]["tmp_name"], $location . $_FILES['uploaded_file']['name']);
$result = $mysqli->multi_query("call sp_upload_file('".$id."','" . $filename . "','".$path."')");
if ($result)
{
do {
if ($temp_resource = $mysqli->use_result())
{
while ($row = $temp_resource->fetch_array(MYSQLI_ASSOC)) {
array_push($rows, $row);
}
$temp_resource->free_result();
}
} while ($mysqli->next_result());
}
if($move)
{
echo "Successfully Uploaded";
}
else
{
echo "File not Moved";
}
}
else
{
echo "File Size Exceeded";
}
}
}
else
{
echo " Invalid File Type";
}
?>
The Html That is used is
<form id = "upload_form" method="post" enctype="multipart/form-data" >
<input type="file" name="uploaded_file" id="uploaded_file" style="color:black" /><br/>
</form>
Basically you need to add to input name [] brackets and attribute "multiple"
<form id = "upload_form" method="post" enctype="multipart/form-data" >
<input type="file" name="uploaded_file[]" multiple="true" id="uploaded_file" style="color:black" /><br/>
</form>
Now all uploaded file will be available via
$_FILES['uploaded_file']['name'][0]
$_FILES['uploaded_file']['name'][1]
and so on
More info at
http://www.php.net/manual/en/features.file-upload.multiple.php

Categories