Load image in PHP


I have a form  (see in attached code)
In the form I have and <input type="file">
I do Browse and select a JPG image.
When I submit the form, I get in the $_POST the name of the file (without its folder),
but $_FILES is empty and 'is_uploaded_file' returns false.
What did I miss?


if (isset($_POST['fileToUpload']))
	if (is_uploaded_file($name))
		if (file_exists($file_name1)) 
		 rename($file_name2, $file_name1);
		 move_uploaded_file($file_name2, $file_name1);
<form action="test1.php" method="post" name="regForm" id="regForm">

File: <input id="fileToUpload" type="file" size="20" name="fileToUpload">
<input name="doRegister" type="submit" id="doRegister" value="Submit">

Open in new window

Who is Participating?
jrm213jrm213Connect With a Mentor Commented:
you need to add to form tag: enctype="multipart/form-data"

<form action="test1.php" method="post" name="regForm" id="regForm" enctype="multipart/form-data">
VapiSoftAuthor Commented:
OK, it works and I will give the points, but maybe you know if I can "show the picture" after the user selects a file and before he click on the submit button?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.