hannnah Posted March 31, 2009 Share Posted March 31, 2009 I'm developing this website, that allows people to register and log in. After logging in, they can add selling on bying- advertisements. In the form, they have to choose a category, then add a headline, description and price, and finally, a picture. I have working scripts for log in and file upload, but just can't figure out how to mix these, so that a certain advertisement has a certain picture and a certain logged in user. In my database, I have tables users, s_advertisements, b_advertisements,categories, subcategories and uploads. Thanks for all the help! I'm very new to programming especially php... Quote Link to comment https://forums.phpfreaks.com/topic/151894-uploading-pictures-for-a-certain-logged-in-user/ Share on other sites More sharing options...
laffin Posted April 16, 2009 Share Posted April 16, 2009 1) post yer sql tables, the table names do no one any good. as far as we are concerned, they could be called a,b,c,d,e,f. they just dont provide enough information to give u any type of help. for all we know, u didnt make a field for the ads image. Quote Link to comment https://forums.phpfreaks.com/topic/151894-uploading-pictures-for-a-certain-logged-in-user/#findComment-811228 Share on other sites More sharing options...
Anxious Posted April 19, 2009 Share Posted April 19, 2009 Uploading images, would be an image field (obviously) then going by the logged in users username on the database, put the image in there. Though for images, it'd make life alot easier for a seperate table called "images" which when the user signs up, there username gets put into that table too, and set it as a primary key. This would be easier because, the main table will have alot of details, passwords etc. and if users upload 15 images... your database will look screwed. It'll work by updating the database, more than entering the first value like you do when you register. I dont know how uploading and downloading images actually work... It's not something Ive looked into, though later on developing my user profiles.. I will end up doing that. I'm dreading it to be honest. Quote Link to comment https://forums.phpfreaks.com/topic/151894-uploading-pictures-for-a-certain-logged-in-user/#findComment-813655 Share on other sites More sharing options...
Pawn Posted April 19, 2009 Share Posted April 19, 2009 If the image you're allowing them to upload is associated with whatever item of content they are creating by entering that form, just store the path in a field within that table and pull it out when you need to display it. Anxious, that part is easy. $maxfilesize = 50000; $maxwidth = 250; $maxheight = 250; if (!is_uploaded_file($_FILES['file_field_name']['tmp_name'])) { $errors[] = "Your image could not be located after upload."; } else { if ($_FILES['file_field_name']['size'] > $maxfilesize) { $errors[] = "Your image's file size exceeded 50kb."; unlink($_FILES['file_field_name']['tmp_name']); } else { $ext = strrchr($_FILES['file_field_name']['name'], "."); if ($ext != ".gif" AND $ext != ".jpg" AND $ext != ".jpeg" AND $ext != ".GIF" AND $ext != ".JPG" AND $ext != ".JPEG" AND $ext != ".png" AND $ext != ".PNG" ) { $errors[] = "The file you uploaded was not a JPG, GIF or PNG."; unlink($_FILES['file_field_name']['tmp_name']); } else { list($width, $height, $type, $attr) = getimagesize($_FILES['file_field_name']['tmp_name']); if ($width > $maxwidth || $height > $maxheight) { $errors[] = "The image you uploaded exceeded ".$maxwidth."x".$maxheight; unlink($_FILES['file_field_name']['tmp_name']); } else { $newname = $_SESSION['username'].$ext; $upload_image = "yes"; $passes++; } } } } Quote Link to comment https://forums.phpfreaks.com/topic/151894-uploading-pictures-for-a-certain-logged-in-user/#findComment-813685 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.