sitefever Posted May 14, 2007 Share Posted May 14, 2007 Ive done some searching, and some previous topics touched on something similar to this, but I could not find an answer. I have a script where you can login to an admin area, insert information into a textbox and the info will be recorded to an SQL database. Then, from the user side, the data is pulled from the database and displayed. For example, on the user side of the site, I have the following line of code: <?php echo $cgi->htmlEncode ( $arow [ "adminname" ] ); ?> This obviously pulls the record in the database of the "adminname" and displays it on the page. ************** What Im looking to do is have an image upload on the admin page which will be uploaded to the site, recorded in the database and displayed on the user side. I cant seem to figure this out and I know that it is pretty simple because it is done all the time. Any help on this would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/51351-upload-img-to-sql-then-display/ Share on other sites More sharing options...
georg Posted May 15, 2007 Share Posted May 15, 2007 You have to create an input-field like this: <input type="file" name="foobar" /> To recieve the file, use the $_FILES - Array: $fp = fopen($_FILES['tmp_name']); $content = fread($fp, $_FILES['size']); fclose($fp); Of cause you should check first, if the file uploaded properly... simply check, if it exists.. But I would advise you not to stor it in the database, beacause there could be large amounts of data... that will maybe slow down your script.. Better store them in the filesystem with reference to the database. Quote Link to comment https://forums.phpfreaks.com/topic/51351-upload-img-to-sql-then-display/#findComment-253356 Share on other sites More sharing options...
radar Posted May 15, 2007 Share Posted May 15, 2007 The way that I do mine -- I have a table in my database called config -- inside it it has a "images_dir" in there with the path to images from the root directory... Then in the admin panel there is a way for people to upload images, it uploads them, but then takes the name of the image and inserts that into a database table as well.. Then for viewing, i simply put the images_dir and the name in the database together... makes for easy modification if you ever needed to do anything. Quote Link to comment https://forums.phpfreaks.com/topic/51351-upload-img-to-sql-then-display/#findComment-253359 Share on other sites More sharing options...
sitefever Posted May 15, 2007 Author Share Posted May 15, 2007 Thanks for the help. Ill see if I can get this to work based on your instructions.... Would anybody be willing to do this for me for a few bucks? To get a better idea of the project, go to www.agentzap.com/agentdemo. All of the info you see on the page, realtor name, company, about me, etc. is all entered in a textbox in the admin area, then displayed on the frontside. I just need to do the same with an image, and I need to resize any uploaded images to a max width/height. My email is jrobinson@sitefever.com Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/51351-upload-img-to-sql-then-display/#findComment-253563 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.