michaelness Posted June 21, 2009 Share Posted June 21, 2009 Basically I have a page called editprofile with this upload form <form enctype="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> Now need the page upload.php to save that image to my database which is called "userinfo" in the row "photo" this is my upload.php form <?php include 'connection.php'; echo '<link rel="stylesheet" type="text/css" href="original.css" />'; $target_path = "pics/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> and then after that I would like a user who is logged into be able to view that image as their profile picture Link to comment https://forums.phpfreaks.com/topic/163177-uploading-image-to-database-and-then-retrieving-it/ Share on other sites More sharing options...
michaelness Posted June 22, 2009 Author Share Posted June 22, 2009 any help at all?? im desperate Link to comment https://forums.phpfreaks.com/topic/163177-uploading-image-to-database-and-then-retrieving-it/#findComment-861255 Share on other sites More sharing options...
flyhoney Posted June 22, 2009 Share Posted June 22, 2009 What do you need help with? If you have a specific problem we can help you, otherwise you are just asking us to do your work for you. There are a lot of PHP image upload tutorials online. I would follow one of those. If you encounter a specific problem, then post here and we can help. Link to comment https://forums.phpfreaks.com/topic/163177-uploading-image-to-database-and-then-retrieving-it/#findComment-861258 Share on other sites More sharing options...
adamlacombe Posted June 22, 2009 Share Posted June 22, 2009 Here's a link to a tutorial: http://php.about.com/od/phpwithmysql/ss/Upload_file_sql.htm Link to comment https://forums.phpfreaks.com/topic/163177-uploading-image-to-database-and-then-retrieving-it/#findComment-861278 Share on other sites More sharing options...
michaelness Posted June 22, 2009 Author Share Posted June 22, 2009 ok, well when I click on upload picture, it copies the picture into the directory "pics" which is good. I want to get the picture name from that directory into the table "userinfo" in the row "photo" This is my upload page. <?php include 'connection.php'; echo '<link rel="stylesheet" type="text/css" href="original.css" />'; //This is the directory where images will be saved $target = "pics/"; $target = $target . basename( $_FILES['photo']['name']); $photo=($_POST['photo']['name']); ; //Writes the information to the database $query = "UPDATE userinfo SET photo = '$photo'"; $result = mysql_query($query); //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> Link to comment https://forums.phpfreaks.com/topic/163177-uploading-image-to-database-and-then-retrieving-it/#findComment-861354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.