0

Hi,
I cant make the file to get uploaded.

index.html

<html>
<body>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>

uploader.php

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Uploader php page</title>
</head>
<body>
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
?> 
</body>
</html>

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by cossay
0

hi. khush

need to know after upload you want to store in local directory or display it on the same page.?

0
This is the first script I wrote when I was learning file uploading. You may find it useful

<?php
//If user has not clicked the upload button, display the upload form
if(!$_POST['upload'])
{
?>
<form method = "post" enctype = "multipart/form-data" action = "upload.php">
<table width = "400" align = "center">
	<tr>
		<input type = "hidden" name = "MAX_FILE_SIZE" value = "120000">
		<td>Picture</td>
		<td><input type = "file" name = "myimage"></td>
	</tr>
	<tr>
		<td></td>
		<td><input type = "submit" name = "upload" value = "UPLOAD"></td>
	</tr>
</table>
</form>
<?php
}
else
{
	//If has clicked the upload button, checked for errors. I like to keep errors in an array 
	//and echo all of them to the user at once as I have done here. You decide how to handle 
	//errors yourself.
	
	if($_FILES['myimage']['error'] == UPLOAD_ERR_INI_SIZE || $_FILES['pic']['error'] == UPLOAD_ERR_FORM_SIZE)
	{
		$my_errors[] = "Picture too large for upload.";
	}
	
	if($_FILES['myimage']['error'] == UPLOAD_ERR_NO_FILE)
	{
		$my_errors[] = "No picture file specified.";
	}
	
	if($_FILES['myimage']['error'] == UPLOAD_ERR_PARTIAL)
	{
		$my_errors[] = "image upload was interrupted.";
	}
	
	if(sizeof($my_errors) > 0)
	{	
		//At least one error occurred so print the errors
		
		echo "File upload failed because of the following error(s) :";
		echo "<ol>";
		for($counter = 0; $counter < sizeof($my_errors); $counter++)
		{
			echo "<li>".$my_errors[$counter]."</li>";
		}
		echo "</ol>";
	}
	else
	{	
		//No errors were found, upload file to the approprite directory
		$destination = "where_you_want_to_store_the_file/".$_FILES['myimage']['name'];
		move_uploaded_file($_FILES['myimage']['tmp_name'], $destination);
		echo "Picture successfully uploaded";
	
	}
	
}
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.