mario margo mario margo -4 years ago 235
Android Question

0 kb when upload and store image to server

i have a table named images. Its have two coloums id and image(varchar300). i have this code upload.php :

$image = $_POST['image'];
$sql ="SELECT id FROM images ORDER BY id ASC";
$res = mysqli_query($con,$sql);
$id = 0;
while($row = mysqli_fetch_array($res)){
$id = $row['id'];
$path = "uploads/$id.png";
$actualpath = "/home/kinanday/public_html/$path";
$sql = "INSERT INTO images (image) VALUES ('$actualpath')";

echo "Successfully Uploaded";
echo "Error";

this is upload.html :

<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="image" />

the problem is :
1. its save on my database but the image in my file manager in Cpanel is 0kb

i using this code to integration to my android app which need an image with varchar type. So in my app doesnot show image anything because the image is 0KB.

can anybody with your advance to fix my php. every answer is very helpfull for me. thanks before .

Answer Source

You need to use the $_FILES superglobal, as @Fred-ii- said. but $image = $_FILES['image'] is a array, see the options for it here:


$image_name = $_FILES['image']['name'];
$image_size = $_FILES['image']['size'];
$image_tmpname = $_FILES['image']['tmp_name'];  // this is a temporary name that php uses on every upload he does.
$image_type = $_FILES['image']['type'];
$image_error = $_FILES['image']['error'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download