Solved

Load image in PHP

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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Responsive Design Tools 6 40
Need help with validating checkout field in WooCommerce 4 47
Time difference 10 36
regex expression 9 23
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

746 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

13 Experts available now in Live!

Get 1:1 Help Now