• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

Load image in PHP

Hi,

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?
<html> 

<?php

if (isset($_POST['fileToUpload']))
{
	$name=$_POST['fileToUpload'];
	if (is_uploaded_file($name))
	{
		$file_name1='data/MyPicture.jpg';
		$file_name2=$_FILES['fileToUpload']["tmp_name"];
		if (file_exists($file_name1)) 
		{
		 unlink($folder);
		 rename($file_name2, $file_name1);
		}
		else
		{
		 move_uploaded_file($file_name2, $file_name1);
		}
	}
}
?>
<body>
<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">
</form>
</body>
</html>

Open in new window

0
VapiSoft
Asked:
VapiSoft
1 Solution
 
jrm213jrm213Commented:
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">
0
 
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?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now