Solved

Load image in PHP

Posted on 2010-09-22
2
228 Views
Last Modified: 2012-05-10
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
Comment
Question by:VapiSoft
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
jrm213jrm213 earned 500 total points
ID: 33734505
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
 

Author Comment

by:VapiSoft
ID: 33734715
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question