jgkgopi Posted May 29, 2011 Share Posted May 29, 2011 I have insert image using this following code but i want to know where it is storing i want file path of the imahe what i have inserted <html> <head><title>File Insert</title></head> <body> <h3>Please Choose a File and click Submit</h3> <form enctype="multipart/form-data" action= "<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="10000000" /> <input name="userfile" type="file" /> <input type="submit" value="Submit" /> </form> </body> <?php // check if a file was submitted if(!isset($_FILES['userfile'])) { echo '<p>Please select a file</p>'; } else { try { upload(); //this will upload your image echo '<p>Thank you for submitting</p>'; //Message after uploading image } catch(Exception $e) { echo $e->getMessage(); echo 'Sorry, could not upload file'; } } // the upload function function upload(){ include "file_constants.php"; $maxsize = $_POST['MAX_FILE_SIZE']; if(is_uploaded_file($_FILES['userfile']['tmp_name'])) { // check the file is less than the maximum file size if( $_FILES['userfile']['size'] < $maxsize) { // prepare the image for insertion $imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name'])); // put the image in the db... // database connection mysql_connect($host, $user, $pass) OR DIE (mysql_error()); // select the db mysql_select_db ($db) OR DIE ("Unable to select db".mysql_error()); // our sql query $sql = "INSERT INTO test_image (image, name) VALUES ('{$imgData}', '{$_FILES['userfile']['name']}');"; // insert the image mysql_query($sql) or die("Error in Query: " . mysql_error()); } } else { // if the file is not less than the maximum allowed, print an error echo '<div>File exceeds the Maximum File limit</div> <div>Maximum File limit is '.$maxsize.'</div> <div>File '.$_FILES['userfile']['name'].' is '.$_FILES['userfile']['size']. ' bytes</div> <hr />'; } } ?> </html> Quote Link to comment https://forums.phpfreaks.com/topic/237747-where-images-are-storing-mysql-databse/ Share on other sites More sharing options...
Psycho Posted May 29, 2011 Share Posted May 29, 2011 i want file path of the imahe what i have inserted There isn't one. The code you have is storing the raw data of the image into the database. There isn't even a "file" with the process you are taking. If you want to display the image you will have to read the data from the database and send it as a jpg image. Here is a page that shows the process in a very rudimentary manner: http://digitalpbk.blogspot.com/2007/04/using-php-for-more-than-html.html Of course, you could go the other way. Instead of storing the raw data in the database you could save the actual file on your server and store the path to the file in your database. Quote Link to comment https://forums.phpfreaks.com/topic/237747-where-images-are-storing-mysql-databse/#findComment-1221772 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.