Solved

Load image in PHP

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

786 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