Jump to content

How does uploading pictures work?


thefollower

Recommended Posts

Like myspace how does it "upload" the images I got a form to give it a try but was wondering as I am using local host I want to test it by uploading to my own hard drive as such... but unfamiliar on 2 things...

 

1) where should it be stored in the htdocs directory precisely?

2) how do sites like myspace etc with hundreds of pictures on their server's know which image is related to which profile ?

 

 

Is it possible to test on local host? Or will i have to buy a real server firstly?

Any help here is much appreciated!

Link to comment
Share on other sites

Do you have a database?

 

1) It should be stored where every you feel the best place is. Personally I store uploaded images in a folder called "images" (Separate from default web page images)

 

2) The database for "MySpace" stores each image along with lots more information, such as:

 

- image filename

- image owner id

- image location

- image upload date

- image album id

- uploader IP address

 

and probably much more.

 

This is so they can associate each image with each user.

 

Link to comment
Share on other sites

Right well im lost though cos then the names would be like:

- image filename

- image owner id

- user name

 

cat45thefollower.jpg

 

But how can you make a script to extract userid to load the correct image.. i can extract names from strings but from a image file in a directory ? is that possible?

Link to comment
Share on other sites

Files are uploaded as binaries with a secondary cluster of information that is associated wtih them such as size, file type,  dates etc.  this is stored in an array called $_FILES (check defined superglobals on php.net)

You process the form via multi-type encrypt with post this passes via binary you deal with the binary on the second page, most servers will actually take the binaries and the file type adn store it in a temporary folder (PHP does this), then from taht temp folder you can do what you wish with it.

Link to comment
Share on other sites

OK, first when a user signs up, he/she is assigned a number from the database.

The number is what relates everything to this person.

Say the user was given the number 100.

When they upload an image, you will place 100 into the database along will the image filename.

When you want to get an image relating to the person, you don't search for the image, but instead

you search for the number 100, and that will give you every image that that person uploaded, since every

image the person uploaded has the number 100 associated to it, and that 100 is associated to the user from

the time of registration.

Link to comment
Share on other sites

yeah.

 

But you will have at least 2 tables.

 

users:

userID    |    firstName    |    lastName

 

 

images:

fileID    |    ownerID    |    fileName

 

 

Here is a basic way to do it:

<?php
session_start();
include 'db.php';
$query = "SELECT * FROM images where ownerID = '{$_SESSION['id']}'";
$sql = mysql_query($sql);
while($row = mysql_fetch_array($sql)){
     echo '<img src="'.$row['fileName'].'" id="Shape1" align="top" alt="" border="0" width="141" height="187">';
}
?>

 

Any number in the ownerID (images table) column will match ONLY ONE number in the userID (users table) BUT ownerID can have an infinite amount of the same number WHERE AS userID MUST be unique.

Link to comment
Share on other sites

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.