php array file is empty when uploading file -
when upload file show array file empty, upload on in php.ini.
please see code blow , let me know error.
i have looked around web solution did not found, im using php version 5.3.25 on centos 5.4 kernel version 2.6.18-164.el5.
thanks , regards
hadi
html page.
<!doctype html> <head> <title>mysql file upload example</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> </head> <body> <form action="add_file.php" method="post" enctype="multipart/form-data"> <input type="file" name="uploaded_file"><br> <input type="submit" value="upload file"> </form> <p> <a href="list_files.php">see files</a> </p> </body> </html>
add_file.php
<?php // check if file has been uploaded if(isset($_files['uploaded_file'])) { // make sure file sent without errors if($_files['uploaded_file']['error'] == 0) { // connect database $dblink = new mysqli('127.0.0.1', 'user', 'pwd', 'mytable'); if(mysqli_connect_errno()) { die("mysql connection failed: ". mysqli_connect_error()); } // gather required data $name = $dblink->real_escape_string($_files['uploaded_file']['name']); $mime = $dblink->real_escape_string($_files['uploaded_file']['type']); $data = $dblink->real_escape_string( file_get_contents($_files['uploaded_file']['tmp_name']) ); $size = intval($_files['uploaded_file']['size']); // create sql query $query = " insert `file` ( `name`, `mime`, `size`, `data`, `created` ) values ( '{$name}', '{$mime}', {$size}, '{$data}', now() )"; // execute query $result = $dblink->query($query); // check if successfull if($result) { echo 'success! file added!'; } else { echo 'error! failed insert file' . "<pre>{$dblink->error}</pre>"; } } else { echo 'an error accured while file being uploaded. ' . 'error code: '. intval($_files['uploaded_file']['error']); } // close mysql connection $dblink->close(); } else { echo 'error! file not sent!'; } // echo link main page echo '<p>click <a href="index.html">here</a> go back</p>'; ?>
Comments
Post a Comment