maminya.aka 0 Newbie Poster

This my form

`<form enctype="multipart/form-data" action="upload.php" method="POST" > 
    <table> 
    <tr> 
    <td>Name :</td> <td><input type="text" placeholder="Name" id="text3"></td> 
    </tr> 

    <tr> 
    <td>Chose File : <input type="file"  name="image" /></td> <td> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"/> 
    </td> 
    </tr> 

    <tr> 
    <td></td> 
    <td><input type="submit" value="upload"/></td> 
    </tr> 
    </table> 
</form>  

`

code to upload image

<?php 
include ("koneksi.php");
// error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
$uploaddir='desain/';

$filename=$_FILES['image']['name'];

$uploadfile=$uploaddir.$filename;

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

$fileSize=$_FILES['image']['size'];

$fileType=$_FILES['image']['type'];


$query ="SELECT count(*) as jum FROM upload WHERE name='$filename'";
$hasil=mysql_query($query);
$data=mysqli_fetch_array($hasil);

if($data['jum']>0)
{
    $query="UPDATE upload SET sze='$fileSize' WHERE name='$filename'";

}
else
{
    $query="INSERT INTO upload (name,type,size,location) VALUES('$filename','$fileType','$fileSize','$uploadfile')" or die ("gagal".mysql_error());
}


if(move_uploaded_file($_FILES['image']['tmp_name'],$uploadfile))

{
    echo "Done";
}
else
{
    echo "Failed";
}

?>

Dani AI

Generated

The PHP notice "Undefined index: images" means the script tried to read $_FILES['images'] but that array key does not exist. In 's case the most common root causes are a name mismatch between the HTML input and the PHP key, the form not being submitted as a multipart POST, the user submitting the form without choosing a file, or PHP rejecting the upload (so $_FILES is empty). Start by confirming what the server actually received.

Quick, reliable checks to add at the top of the upload handler:

var_dump($_SERVER['REQUEST_METHOD'], $_FILES);
if (!isset($_FILES['images']) || $_FILES['images']['error'] !== UPLOAD_ERR_OK) {
    // handle missing upload or inspect the error code
}

If $_FILES is empty after a submit, check php.ini limits (upload_max_filesize, post_max_size) and that the target directory exists and is writable. Use the UPLOADERR constants to get the exact failure reason (see the file-upload errors doc). Always validate and sanitize file names (do not trust client names), check move_uploaded_file() return values, and keep error reporting on while debugging.

As a longer-term fix: avoid mixing mysql and mysqli, migrate to mysqli or PDO with prepared statements, and enable detailed errors during development (error_reporting(E_ALL); ini_set('display_errors',1);). For authoritative details see the PHP file upload documentation: Handling file uploads - Manual and $_FILES - Manual.

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.