Jump to content

Recommended Posts

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...

  • 3 weeks later...

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.

 

 

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.

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++;
		}
	}
        }
} 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.