Solved

Load image in PHP

Posted on 2010-09-22
2
224 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Please show me easiest post form. 3 31
only allow numbers with preg match 4 25
updating the date data 12 21
How to count in a table in php 22 0
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now