| mysql file upload
|
tr8er8

msg:3579115 | 7:27 pm on Feb 19, 2008 (gmt 0) | Ok Im trying to upload files and have them stored in a table on mah database, but its not working out at all. I've been trying the whole day and can't get anything to work. Here is my code: <html> <body> <h3>Please Choose a File and click Submit</h3> <form enctype="multipart/form-data" action="" method="post"> <input name="userfile[]" type="file" /> <input type="submit" value="Submit" /> </form> </body> </html> <?php // the upload function function upload(){ if(is_uploaded_file($_FILES['userfile']['tmp_name'])) { // prepare the image for insertion $imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name'])); // $imgData = addslashes($_FILES['userfile']); // get the image info.. $size = getimagesize($_FILES['userfile']['tmp_name']); // put the image in the db... // database connection mysql_connect($mysql_server, $mysql_user, $mysql_password) OR DIE (mysql_error()); // select the db mysql_select_db ("database") OR DIE ("Unable to select db".mysql_error()); // our sql query $sql = "INSERT INTO test ( image_id , image_type ,image, image_size, image_name) VALUES ('', '{$size['mime']}', '{$imgData}', '{$size[3]}', '{$_FILES['userfile']['name']}')"; // insert the image if(!mysql_query($sql)) { echo 'Unable to upload file'; } } } ?>
|
Demaestro

msg:3579123 | 7:30 pm on Feb 19, 2008 (gmt 0) | Are you getting any errors or is it just not inserting anything and not erroring?
|
estevan

msg:3579134 | 7:39 pm on Feb 19, 2008 (gmt 0) | hello i hope this help change $imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name'])); to $tempfile = fopen($_FILES['userfile']['tmp_name'],'rb'); $filedata = fread($tempfile,filesize($uploadfile)); $imgData = addslashes($filedata); if no work please post the error
|
|
|