Click here to Skip to main content
14,921,361 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I am getting a problem on uploading a file to database and to the "upload" directory,

I have a database named "saide_db", table named "userfiles", and "upload" directory for my uploaded files. I can tell that upload.php file is working fine on local even connecting with remote database, but when I try to upload a file, it always executes only the "Please select file to upload!" function resulting to "upload" directory always empty, even though I have a file included in the upload form.

Pls check the "upload.php" code below and let me know if you find any error/s and have a suggested solution/s. Thank you.

What I have tried:


		$errors = array();
		$extension = array("jpeg","jpg","png","gif");
		$bytes = 1024;
		$allowedKB = 100;
		$totalBytes = $allowedKB * $bytes;
			echo "Please select file to upload!";
		$conn = mysqli_connect("localhost","root","","saide_db");	
		foreach($_FILES["files"]["tmp_name"] as $key=>$tmp_name)
			$uploadThisFile = true;

				array_push($errors, "File type is invalid. Name:- ".$file_name);
				$uploadThisFile = false;
			if($_FILES["files"]["size"][$key] > $totalBytes){
				array_push($errors, "File size must be less than 100KB. Name:- ".$file_name);
				$uploadThisFile = false;
				array_push($errors, "File already exists. Name:- ". $file_name);
				$uploadThisFile = false;
				$query = "INSERT INTO userfiles(FilePath, FileName) VALUES('Upload','".$newFileName."')";
				mysqli_query($conn, $query);			
		$count = count($errors);
		if($count != 0){
			foreach($errors as $error){
				echo $error."<br/>";
Updated 13-Feb-20 22:15pm

1 solution

if (isset($_FILES["files"]) == false)
   echo "Please select file to upload!";
If you get to the echo line, it means that the global $_FILES["files"] is not set.

Here's a link to a page explaining how to deal with uploads in a more secure way:
PHP: Handling file uploads - Manual[^]
Re-check twice the name attribute of the input tag on HTML side. According to your PHP code, you should have something like <input name="files" ... >.
Xavier Benedict Astor 17-Feb-20 1:32am
Hello, already tried editing the "echo "Please select"" part of the code. Also upon checking, seems my html form code is all good. But unfortunately, still getting the same result.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900