I am working on a social network site with php and mysql. I was wondering which way would be the most efficient way of uploading the users pics to the server into a file folder or directly into the database? Also I was wondering would it be easier to save all the pictures into one table or is it possible to create a table for each users pictures?

There are many decent file uploads out there, on a personal note, for the images themselves i would have my users table and link to an image table and have a row which stores the users id in the images table then they all stay the same...... if that makes any sense!

Hope it helps!

There are many decent file uploads out there, on a personal note, for the images themselves i would have my users table and link to an image table and have a row which stores the users id in the images table then they all stay the same...... if that makes any sense!

Hope it helps!

So you mean use one specific table for all members of the website that stores the pictures and that has there user_id in one of the rows for differintiating who uploaded the pictures.

So you mean use one specific table for all members of the website that stores the pictures and that has there user_id in one of the rows for differintiating who uploaded the pictures.

Also do you mean example codes and tutorials online for file uploading or is there some sort of file uploading software. Sorry if these questions seem like a 2 year old is asking them, but I am just getting used to php

Don't worry about the questions, thats what we are here for!

If you search for a php upload script i'm sure you will find somthing that will suit your needs, i was meaning a script not software!

As for the table let me help you out.

users table has (lets say);
id | username | fullname | password | email | access |

then in the picture table;

id | user_id | name | type | size | path

then when you do the mysql_query the user id has the same id a the uploaded images.

Do you get me so far?

Here is a quick upload script to get you going, it's pretty basic and vunerable but it give you an idea...

<?php
// EDIT USER AND PASSWORD INFO
$dbhost = 'localhost'; //MYSQL HOSTNAME
$dbuser = 'username'; // MYSQL USERNAME
$dbpass = 'password'; //MYSQL PASSWORD

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to database');
// EDIT DATABASE
$dbname = 'your-database'; // DATABASE NAME
mysql_select_db($dbname);
?>
<form method="post" enctype="multipart/form-data">


<input name="userfile" type="file" id="userfile">
<input name="upload" type="submit"  value=" Upload ">
</form>
<?php
if (isset($_POST['upload'])){
	// FULL PATH TO THE UPLOAD FOLDER
$uploadDir = 'c:/wamp/www/uploads/';
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];


$filePath = $uploadDir . $fileName;

$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}



if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
} 
// YOU WILL NEED TO MAKE SURE ALL THE ROWS ARE CORRECT, THIS IS JUST AN EXAMPLE
$query = "INSERT INTO uploads (name, size, type, path ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";

mysql_query($query) or die('Error, query failed : ' . mysql_error()); 



echo "<br>Files uploaded<br>";
}



?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.