0

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>
4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by IIM
0

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.

0

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

0

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

0

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

0

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

This topic has been dead for over six months. 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.