graham23s Posted March 4, 2007 Share Posted March 4, 2007 Hi Guys, What im trying to do is make a form with the usual username,password, and email fields but at the bottom before the form is submitted there is an option to upload a photo, i have made the code this: <input name="userfile" type="file" size="50" /> theres no upload button as the main button at the bottom of the form is meant to pass all the fields including the upload file one, but im not sure whats the best way to handle the upload, i put the "userfile" into variable on the submitted page but should that go into the MySQL database (the photo i mean) or is there another way to do this. hope that made sense lol cheers Graham Link to comment https://forums.phpfreaks.com/topic/41167-uploading-images-in-php/ Share on other sites More sharing options...
pocobueno1388 Posted March 4, 2007 Share Posted March 4, 2007 You can make it upload the file into a directory, then store the ending name of the file in the database. Say your directories name was "photos" and the file the person just uploaded was named picture.jpg. You store the entire file into your directory, and then store picture.jpg into the database. To display the picture you select the picture.jpg from the database and echo it like this. <?php $filename = "picture.jpg"; echo "<img src='photos/$filename'>"; ?> Link to comment https://forums.phpfreaks.com/topic/41167-uploading-images-in-php/#findComment-199397 Share on other sites More sharing options...
graham23s Posted March 4, 2007 Author Share Posted March 4, 2007 Hi mate, I have made it so, when a user registers they are given a folder (called they're username) inside a members folder: members/graham23s That sounds like what i'm after thanks mate, so from the form i take the variable say it's "usersphoto" from the main registration page is that right? cheers Graham Link to comment https://forums.phpfreaks.com/topic/41167-uploading-images-in-php/#findComment-199433 Share on other sites More sharing options...
pocobueno1388 Posted March 4, 2007 Share Posted March 4, 2007 Whatever variable holds the file's name that the user uploaded is what you want to insert into the database. You want to upload the entire file name into the users folder (members/graham23s). Entire name: www.your-site.com/members/graham23s/file.jpg what you should store in the database: graham23s/file.jpg I don't know what your "userphoto" variable holds without seeing your code. Hopefully that will clear it up for you though. Link to comment https://forums.phpfreaks.com/topic/41167-uploading-images-in-php/#findComment-199462 Share on other sites More sharing options...
graham23s Posted March 5, 2007 Author Share Posted March 5, 2007 Hi mate, Thanks for your help. all the "userphoto" bit was is this: <input name="userphoto" type="file" id="ufile" size="50" /> on the main registration page i changed it to photo to make it easier. when the page was submitted (along with the test .jpg) in MySQL it printed the entire path to the file instead of userspic.jpg,, is there a way to only have the pictures name rather than the full path. C:\Documents and Settings\Graham\Desktop\Testpic.jpg thanks a lot Graham Link to comment https://forums.phpfreaks.com/topic/41167-uploading-images-in-php/#findComment-199492 Share on other sites More sharing options...
pocobueno1388 Posted March 5, 2007 Share Posted March 5, 2007 Okay, you can store the file name in a variable like this. $file = $_FILES["file"]["name"]; Then if you don't insert it into the database on the first page, you probably need to store it into a hidden field to get it to your second page where you can add it to your database. Link to comment https://forums.phpfreaks.com/topic/41167-uploading-images-in-php/#findComment-199514 Share on other sites More sharing options...
graham23s Posted March 7, 2007 Author Share Posted March 7, 2007 Thanks mate, sorry i meant to reply earlier, that worked great i am now 1 step ahead in this area lol cheers Graham Link to comment https://forums.phpfreaks.com/topic/41167-uploading-images-in-php/#findComment-201520 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.