hi guys i am trying to upload an image but my code is not upload image size higher than 400bytes please help me i tried but many thing but figure it out.

<html>
<head>



</head>
<body>


<form action="test.php" method="post" enctype="multipart/form-data" >

  File:
<input type="file" name="image" />
<input type="submit" value="Upload"  />

</form>


<?php


mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("n") or die(mysql_error());

 $file = $_FILES['image']['tmp_name'];





 
 
 
if(!isset($file))
echo "please select an image";
else
{
	
 $image = file_get_contents($_FILES['image']['tmp_name']);
 $image_name = $_FILES['image']['name'];
 $image_size = getimagesize($_FILES['image']['tmp_name']);

echo $size   =   $_FILES['image']['size'];
 $height =    $_FILES['image']['height'] /100;
 $width  =    $_FILES['image']['width'] /100;

 
 
 if($image_size==FALSE)
 echo "that's not an image";
 else
 {
	 
	if(!$insert = mysql_query("INSERT INTO parent_info VALUES ('','$image_name','$image')"))
	echo "problem";
	else
	{
		
	
	
}

 }}




?>


</body>
</html>

Recommended Answers

All 6 Replies

Upload to where ? You've not upload to any destination. You've need 'move_uploaded_file' function to store the image from the temp directory to destination folder which you want to store. Example like below

move_uploaded_file('image_name', 'destination');

The complete info here.

i am uploading it to mysql database

To insert image into the table "n";
1. Modify line 25 as

$conn = mysql_connect("localhost","root","") or die(mysql_error());

2. Line 57 should be

if(!$insert = mysql_query("INSERT INTO parent_info VALUES ('','$image_name','$image')", $conn))

make sure the size allocated to the image field is higher than 400bytes

Or another alternative is to move the image as shown by Zero13 and then insert the filelocation into database...

some images are being uploaded and some are not. i couldn't figure it out the reason behind this even my code is pretty clean but still got the same problem

If that's the problem then you must increase the file upload limit size....
You can do this change in your php.ini

upload_max_filesize = 10M

For more information ..Click HERE

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.