I'm trying to upload an image through a contact form, to get a server in a particular folder and its time to visualize the database. When I submit the form I get this error:
File is an image - image/jpeg. Notice: Undefined index: fileToUpload
in C:\xampp\htdocs\Web\form.php on line 68 Notice: Trying to access
array offset on value of type null in C:\xampp\htdocs\Web\form.php on
line 68 Notice: Undefined index: image in C:\xampp\htdocs\Web\form.php
line 82
This is the code:
HTML:
<div class="container-form">
<form action="form.php" method="post" enctype="multipart/form-data">
<div class="image">
Прикачете ваша снимка! (максимален размер 20МБ)<br>
<input type="file" name="image" id="image" size="40" required="true" />
</div>
<div class="submit">
<input type="submit" name="submit" value="Изпращане" id="submit" />
</div>
</form>
</div>
PHP:
// Connect to MyQSL
$link = mysqli_connect("localhost", "root", "", "form");
$link->query("SET NAMES 'UTF8'");
// Check our connection
if ($link === false)
{
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["image"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["image"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 20000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" ) {
echo "Sorry, only JPG, JPEG and PNG files are allowed.";
$uploadOk = 0;
}
// Escape user inputs for security
$name = mysqli_real_escape_string($link, $_REQUEST['name']);
$date = mysqli_real_escape_string($link, $_REQUEST['date']);
$image = mysqli_real_escape_string($link, $_REQUEST['image']);
// Insert our data
$sql = "INSERT INTO form (name, date, image) VALUES ('$name', '$date', '$image')";
// Print response from MyQSL
if (mysqli_query($link, $sql))
{
echo "<div class='echo-complete'> <div class='echo-text'> Формата беше приета успешно. Благодарим ви.";
}
else
{
echo "<div class='echo-error'> <div class='echo-text'> ГРЕШКА: Не може да се изпълни $sql." .
mysqli_error($link);
}
// Close our connection
mysqli_close($link);
Database:
image column is type BLOB
<div class="container-form">
<form method="post" enctype="multipart/form-data">
<div class="image">
<input type="file" name="image" id="image" size="40" required="true" />
</div>
<div class="submit">
<input type="submit" name="submit" value="Upload" id="submit" />
</div>
</form>
</div>
<!--Now we will connect to the database.-->
<?php
// define file
if (isset($_POST["submit"])) {
$fname = $_FILES["image"]["name"];
$fsize = $_FILES["image"]["size"];
$ferror = $_FILES["image"]["error"];
$ftype = $_FILES["image"]["type"];
$ftmp = $_FILES["image"]["tmp_name"];
// Get the extension of the file and verify if we support it
$allowed = array(
"png",
"jpeg",
"jpg",
"gif"
); //make sure it's not capital letters.
$actual_extension = explode(".", $fname); // Get what we have after the . on the file name
$extension = end($actual_extension); // make sure we got the extension
//check if the extension is supported.
if (!in_array($extension, $allowed)) {
echo "Sorry! We do not support this format" . "<br>";
}
// Now check if we have a file error, else: upload
if ($ferror == 1) { // Check if we have an error
echo "Something went wrong" . "<br>";
} else {
if ($fsize > 100000) { // check if the uploaded file matches the size we allow.
echo "Your file is BIG" . "<br>";
} else {
$new_name = uniqid('', true); // we will give the uploaded file a unique id
$path = "uploads/" . $new_name . "." . $extension; // Define the path and upload the file with new name+ "." + the file extension.
if (move_uploaded_file($ftmp, $path)) {
echo "file uploaded succesfully";
} else {
echo "something went wrong with the file upload";
}
}
}
$link = mysqli_connect("localhost", "root", "", "sadik");
$query = "INSERT INTO `table` (`image`) VALUES ($new_name) ";
mysqli_query($link, $query);
// ...
}
?>
Related
I have made a form on php and I am adding an image input option there.
<form action="./assets/actions/gallery_post.php" id="upload-form" method="POST">
<input type="text" name="title" placeholder="Image title..." class="form-control" required>
<br>
<input type="text" name="description" placeholder="Image description..." class="form-control">
<br>
<input type="file" name="file", class="form-control" required>
<br>
<button type="submit" name="picture-submit" class="form-control submit">Upload Photo</button>
</form>
The following is my php code to upload the file.
// Check if the button was pressed
if (isset($POST['picture-submit'])) {
echo "Entered";
// Get the inputs
$newfilename = 'gallery';
$title = $_POST['title'];
$description = $_POST['description'];
$file = $_FILES['file'];
if($file){
echo "FILE";
}else{
echo "No File found";
}
console.log($file);
// Obtaining some file information
$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileError = $file['error'];
$fileType = $file['type'];
// Checking file extensions
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
echo "$fileActualExt";
// Allowed extensions
$allowed = array('jpeg', 'jpg', 'png', 'JPG');
// if extension is allowed
if(in_array($fileActualExt, $allowed)){
// check if any error
if($fileError === 0){
// Creating a unique file name
$fileNew = $newfilename. "." . uniqid('', true) . "." . $fileActualExt;
$fileDest = "assets/images/gallery/" . $fileNew;
// Function to upload file
move_uploaded_file($fileTmpName, $fileDest);
// Making a database connection
include_once ('dbh.php');
$stmt = mysqli_stmt_init($conn);
// Move to the database as well using prepared statements
$sql = "INSERT into gallery(location, title, description) VALUES(?, ?, ?)";
echo $sql;
// Binding parameters
mysqli_stmt_bind_param($stmt, "sss", $fileDest, $title, $description);
mysqli_stmt_execute("$stmt");
// Perform a query, check for error
mysqli_query($conn, $sql) or die(mysqli_error($conn));
echo "Query Sent";
header("Location: ../gallery.php?upload=sucess");
}else {
echo "There was an error in file upload.";
}
}else {
echo "You cannnot upload files of this type!";
}
}
It is not even entering the if condition in the above scenario. When I remove the if condition, I get "No file Found". Sort of stumped here now because I have made it work in the past. I even tried the basic HTML query format like this mysqli_query($conn, $sql) or die(mysqli_error($conn)); and this does not work either.
Your form tag has to be enabled enctype="multipart/form-data".
Try this code.
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
?>
I want to upload two images, one of the user and second of his ID, using one submit button using mysqli. Here is my HTML.
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
your image: <input type="file" name="img"><br/>
your Id card: <input type="file" name="img2">
<input type="submit" name="publish" value="upload">
</form>
</body>
</html>
All I know is to upload the single image at a time but what if want to upload these image into the database with single submit. I am not writing PHP because I don't know how to do this. I can upload multiple images at a time using an array but I want to use this method. Is it possible to do with PHP??
PHP for single upload:
<?php
$dir = "uploads/";
$t_file = $dir . basename($_FILES["img"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($t_file,PATHINFO_EXTENSION));
if(isset($_POST["upload"])) {
$check = getimagesize($_FILES["img"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
?>
I can do it by using javascript. All respected users, please be more helpful for those who are new to any language. Or make this website only for experts, not for beginners.
So I use PHP for my first upload and JS for my second image upload.
here is js:
<script>
function startUpload(){
document.getElementById('uploadProcess').style.visibility = 'visible';
document.getElementById('uploadForm').style.visibility = 'hidden';
return true;
}
function stopUpload(success,uploadedFile){
var result = '';
if (success == 1){
result = '<span class="sucess-msg">The file was uploaded successfully!<\/span><br/><br/>';
//Uploaded file preview
var embed = document.getElementById("UploadedFile");
var clone = embed.cloneNode(true);
clone.setAttribute('src',uploadedFile);
embed.parentNode.replaceChild(clone,embed);
}else {
result = '<span class="error-msg">There was an error during file upload!<\/span><br/><br/>';
}
document.getElementById('uploadProcess').style.visibility = 'hidden';
document.getElementById('uploadForm').innerHTML = result + '<label>File:<input name="myfile" type="file" size="30" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>';
document.getElementById('uploadForm').style.visibility = 'visible';
return true;
}
</script>
The html:
<form action="upload.php" method="post" enctype="multipart/form-data" onsubmit="startUpload();">
<p id="uploadForm">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="file" name="myfile" id="fileToUpload1">
<input type="submit" value="submitBtn" name="submit">
</p>
</form>
and the upload.php:
<?php
$success = 0;
$uploadedFile = '';
//File upload path
$uploadPath = 'uploads/';
$targetPath = $uploadPath . basename( $_FILES['myfile']['name']);
if(#move_uploaded_file($_FILES['myfile']['tmp_name'], $targetPath)){
$success = 1;
$uploadedFile = $targetPath;
}
sleep(1);
?>
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
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["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
I'm trying to upload a file to a server then display it to the user. I'm having difficulties to display the image to the user.
If you could provide code that helps me out to display the image to the user. The code should fit in the php file right under //Display image here <---------
html file
<html>
<body>
<form method="post" enctype="multipart/form-data" action="server.php">
<input type="file" name="fileToUpload" id="fileToUpload" size="35">
<br>
<br>
<input type="submit" value="Upload" name="upload">
</body>
</html>
php file
<?php
if(isset($_FILES["fileToUpload"])){
$file = $_FILES['fileToUpload'];
$fileName = $_FILES["fileToUpload"]["name"];
$fileTmpName = $_FILES["fileToUpload"]["tmp_name"];
$fileSize = $_FILES["fileToUpload"]["size"];
$fileError = $_FILES["fileToUpload"]["error"];
$fileType = $_FILES["fileToUpload"]["type"];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png');
if(in_array($fileActualExt, $allowed)){
//Image code
if($fileError === 0){
if($fileSize < 500000){
$fileDestination = 'uploads/'.$fileName;
move_uploaded_file($fileTmpName, $fileDestination);
header("Location: server.php?uploadsuccess");
//Display image here <----------
}else{
echo "Your file is too big!";
}
}else{
echo "There was an error while uploading your file!";
}
}else{
if(isset($_FILES["fileToUpload"])){
$file = $_FILES["fileToUpload"]["name"];
echo "File: ".$file;
}
}
}
?>
first you have to change .html file to .php and note that i have renamed file as index.php
<html>
<body>
<?php if(isset($_GET['filename'])){ ?>
<img src="<?php echo $_GET['filename']; ?>" />
<?php } ?>
<form method="post" enctype="multipart/form-data" action="server.php">
<input type="file" name="fileToUpload" id="fileToUpload" size="35">
<br>
<br>
<input type="submit" value="Upload" name="upload">
</body>
</html>
server.php
<?php
if(isset($_FILES["fileToUpload"])){
$file = $_FILES['fileToUpload'];
$fileName = $_FILES["fileToUpload"]["name"];
$fileTmpName = $_FILES["fileToUpload"]["tmp_name"];
$fileSize = $_FILES["fileToUpload"]["size"];
$fileError = $_FILES["fileToUpload"]["error"];
$fileType = $_FILES["fileToUpload"]["type"];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png');
if(in_array($fileActualExt, $allowed)){
//Image code
if($fileError === 0){
if($fileSize < 500000){
$fileDestination = 'uploads/'.$fileName;
move_uploaded_file($fileTmpName, $fileDestination);
// header("Location: server.php?uploadsuccess");
//Display image here <----------
header("Location:index.php?filename=$fileDestination");
}else{
echo "Your file is too big!";
}
}else{
echo "There was an error while uploading your file!";
}
}else{
if(isset($_FILES["fileToUpload"])){
$file = $_FILES["fileToUpload"]["name"];
echo "File: ".$file;
}
}
}
?>
I have done using php but better option is using ajax call .just google it you will get man examples
To be able to display the image, do this :
//Display image here <----------
echo "<img src='" . $fileLocation . "'>";
Replace $file_location with the variable containing the file location
<!-- index.php -->
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file2upload">
<input type="submit" value="upload">
</form>
<!-- sorry i didn't got php code section here , so i m posting php file code here -->
<!-- upload.php file -->
<?php
// target directory where files goes after uploading
$target_dir = "uploads/pictures/";
// target files name and extension save to this target_file variable
// $target_file specifies the path of the file to be uploaded
$target_file = $target_dir . basename($_FILES["file2upload"]["name"]);
$uploadOk = 1;
// checking that target_file is been uploading is a true image file extenion or not
// $audioFileType holds the file extension of the file (in lower case)
$picFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
echo $picFileType."<br />";
if(isset($_POST["submit"])) {
// The filesize() function in PHP is an inbuilt function which is used to return the size of a specified file.
// The filesize() function accepts the filename as a parameter and returns the size of a file in bytes on success and False on failure.
$check = getimagesize($_FILES["file2upload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// step:2
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// step: 3
// Check file size
if ($_FILES["file2upload"]["size"] > 5000000) { // 5MB manual set
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// step: 4
// Allow certain file formats
if($picFileType != "jpeg" && $picFileType != "jpg" && $picFileType != "bmp" && $picFileType != "gif" && $picFileType != "png" ) {
$uploadOk = 0;
echo "<b style='color:red;'> File to be uploading is not have image formates like : .jpeg,.jpg,.bmp, .gif, .png etc </b><br />";
}
// step: 5
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["file2upload"]["tmp_name"], $target_file))
{
echo "The file ". basename( $_FILES["file2upload"]["name"]). " has been uploaded. <br />";
<!-- this is the ANSWER -->
<!-- ----------------------------- -->
echo $file_name = basename( $_FILES["file2upload"]["name"]);
echo $file_size = $_FILES["file2upload"]["size"];
echo $fileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
<!-- ----------------------------- -->
}
else {
echo "Sorry, there was an error uploading your file.";
}
}
// }else{ echo "<b style='color:red;'> form have diffrent method ( post/get ) </b><br />"; $uploadOk = 0; }
?>
So guys.. I want to upload an image to a certain folder name "uploads" and insert the name of that image on database, the problem is that he isn't uploading the image..
So i have this basic HTML code:
<form action="newimage.php" method="POST">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="form-group">
<input type="file" name="pic" id="pic">
</div>
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
And this is my PHP page
<?php
$mysqli = new mysqli("localhost", "root", "", "homepage");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$name = "somethinghere";
#do upload
$target_dir = "uploads";
$temp = explode(".", $_FILES["pic"]["name"]);
$newfilename = $target_dir . '/Foto-' . $name . '.' . end($temp);
if (move_uploaded_file($_FILES['pic']['tmp_name'], $newfilename) ) {
$productimage = 'Foto-' . $name . '.' . end($temp);
}
else
{
$productimage = '';
}
$sql = "INSERT INTO galeria_front (image_name) VALUES ('$productimage')";
if ($mysqli->query($sql) === TRUE) {
header("Location: galery.php");
} else {
echo "Error: " . $sql . "<br>" . $mysqli->error;
}
$mysqli->close();
?>
As you can see i have a conection which works, and tried to insert the productimage into the database table but for some reason , it's entering the else{} and making my productimage empty on the database which means the above upload isn't working.
P.S(Pardon me for any bad english)
try adding these
<form action="newimage.php" method="POST" enctype="multipart/form-data">
</form
Alter your script into this
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$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["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType !=
"jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))
{
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been
uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
https://www.w3schools.com/php/php_file_upload.asp
you are missing enctype="multipart/form-data"
<form action="/process.php" method="post" enctype="multipart/form-data"></form>
I want to upload an file from form and when I click submit it uploads the file to the server and insert filename, filesize and filetype from that file. but I always get errors like:
Warning: "filesize(): "stat failed for "uploadedfile" in C:\wamp\www\Project2\members\uploaded.php on line 14"
Warning: filetype(): "Lstat failed for "uploadedfile" in C:\wamp\www\Project2\members\uploaded.php on line 15"
Here is my uploadfile.php:
<html>
<body>
<?php
session_start();
$username =$_SESSION["uname"];
?>
<title>Uploading Page</title>
<b>Hello again,<?php echo $username ?>. From here, you can select your image or file and upload our database.</b>
<form action="uploaded.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form></tr>
</table>
</form>
</body>
</html>
and here is my uploaded.php:
<html>
<body>
<title>Uploading Page</title>
<?php
session_start();
$username =$_SESSION["uname"];
?>
<?php
$con = mysqli_connect("localhost", "root", "", "webpage");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$filename = basename($_FILES["fileToUpload"]["name"]);
$filesize = filesize($_FILES["fileToUpload"]["name"]);
$filetype = filetype($_FILES["fileToUpload"]["name"]);
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$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["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "<br>File is an image - " . $check["mime"] . ".</br>";
$uploadOk = 1;
} else {
echo "<br>File is not an image.</br>";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "<br>Sorry, file already exists.</br>";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000000000000) {
echo "<br>Sorry, your file is too large.</br>";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "<br>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</br>";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "<br>Sorry, your file was not uploaded.</br>";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
$sql=mysqli_query($con,"insert into datas(username,imagesnotes,size,type) values('$username','$filename','$filesize')");
if(!$sql)
{
echo "<br>there is a problem in MySQL please check again.</br>";
}
echo "<br>The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.</br>";
} else {
echo "<br>Sorry, there was an error uploading your file.</br>";
}
}
mysqli_close($con);
?>