Kartikay Anand Kartikay Anand - 1 year ago 87
MySQL Question

failed to open stream error for uploaded image

HTML code:

<input type="file" name="files[]" multiple="multiple" id="photo" >

PHP code:

$query1="insert into imgtab values('".$ka."','".addslashes(file_get_contents($_FILES['files']['name'][$i]))."')";


Warning: file_get_contents(Screenshot (5).png): failed to open stream: No such file or directory in C:\xampp\htdocs\q.php on line 16

How can I solve this error?

Answer Source

Try using file_get_contents($_FILES['files']['tmp_name'][$i]) instead since ['name'] is a reference to the uploaded file name, not the file location. It is also bad practice to store files in the database. So you'd best use move_uploaded_file(...) then store the location to your database rather than the actual file contents.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download