[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Load image in PHP

Posted on 2010-09-22
2
Medium Priority
?
231 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

650 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