Hi, i found this image uploader in another post but i'm having a few problems with errors or upload confirmation not displaying at all and was wondering if someone could take a look.

original thread,the file is a zip near the bottom of the page

It seems the database code was disabled so i have made a few adjustments allowing me to upload the details to my own database.I dont think i have caused this with the changes i have made, this could be a possibility though so here is the file.

Recommended Answers

All 2 Replies

What are the errors ? … and to be at the root of things … what are you trying to do and how are you planning to do them ? … tell us and I will give you feed back in how to do

If you all you want to do is to upload an image, then try this simple one.

<?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";
	
	}
	
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.