roonnyy Posted September 20, 2008 Share Posted September 20, 2008 Hi guys! I have got small problem. First of all what I want to do: select file then click upload button and save this file to database. I have got script that works (almost ). My problem is that i can't make this script working with upload form. If someone could help me I have be glad he is scirpt: <? if (isset($_POST['submit'])) { include("pg.php"); //script with database connection and others commands for file insert $filetosave=($_FILES['userfile']); // file to save in the database $loId = addImage($conn,$filetosave); $id_Desc = $filetosave; $fsize=filesize("$filetosave"); $sql = "INSERT INTO file(name,image,filesize) VALUES('$id_Desc','$loId','$fsize')"; pg_query($sql); } ?> <form enctype="multipart/form-data" action="<?php echo $PHP_SELF; ?>" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="512000" /> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> Link to comment https://forums.phpfreaks.com/topic/125103-solved-select-file-via-form-and-insert-into-database/ Share on other sites More sharing options...
BenInBlack Posted September 20, 2008 Share Posted September 20, 2008 the problem is here: $filetosave=($_FILES['userfile']); $_FILES['userfile'] is a reference to aspects of the file uploaded if you need just the file name then use $filetosave=$_FILES['userfile']['name'] If you eed to bring in the contents of the file //read image from tmp file $ffile = fopen($_FILES['userfile']['tmp_name'],"rb"); $contents = fread($ffile,$_FILES['userfile']['size']); fclose($ffile); $contents variable no holds the contents of the file Link to comment https://forums.phpfreaks.com/topic/125103-solved-select-file-via-form-and-insert-into-database/#findComment-646573 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.