Jump to content

Need help to finish my site.


justAnoob

Recommended Posts

I have images on my server in the folder "userimages". I have several sub foloders off of that (computers, students, and so on). Uploading the picture to the server is no problem. Displaying the pictures from the server is easy also... But right now I'm calling them straight from the server. What I want to do is when a picture is uploaded, the picture goes to the server(done), and then the info goes to mysql(done except for image path). The reason I want to do this is because it seems easier to call everything from mysql so it can display inside a neat table on my page. Understand what I'm saying. Here is the upload so far.

<?php
session_start();

$host = "0000000000";
$username = "0000";
$password = "00000000";
$db_name = "0000000000";
$tbl_name1 = "00000";
$tbl_name2 = "000000000000";

mysql_connect("$host", "$username", "$password") or die("Could not connect.");
mysql_select_db("$db_name") or die("Could not find database");

$item_name = mysql_real_escape_string($_POST['item_name']);
$description = mysql_real_escape_string($_POST['description']);
$in_return = mysql_real_escape_string($_POST['in_return']);
$imgpath = ????????

define ("MAX_SIZE","1000");
function getExtension($str)
{
$i = strrpos($str,".");
if (!$i)
{
	return "";
}
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

$errors=0;
if(isset($_POST['Submit']))
{
$image=$_FILES['image']['name'];
if ($image)
{
	$filename = stripslashes($_FILES['image']['name']);
	$extension = getExtension($filename);
	$extension = strtolower($extension);
	if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "gif") && ($extension != "png"))
	{
		echo '<h1>Unknown extension!</h1>';
		$errors=1;
	}
	else
	{
		$size=filesize($_FILES['image']['tmp_name']);
		if ($size > MAX_SIZE*1024)
		{
			echo '<h1>You have exceeded the size limit!</h1>';	$errors=1;
		}

		$category = $_POST['listmenu'];
		$image_name=time().'.'.$extension;
		$newname="userimages/$category/".$image_name;
		$copied = copy($_FILES['image']['tmp_name'], $newname);

		if (!$copied)
		{
			echo '<h1>Copy unsuccessfull!</h1>';
			$errors=1;
		}
	}
}
}



$findit = $_SESSION['id'];
$result=mysql_query("SELECT id FROM members WHERE username = '$findit'");
$row=mysql_fetch_assoc($result);
$user_id = $row['id'];
$sql = "INSERT INTO member_trades(item_name, description, in_return, user_id)VALUES('$item_name','$description','$in_return', '$user_id')";
mysql_query($sql) or die(mysql_error());


if(isset($_POST['Submit']) && !$errors)
{
header ("http://www.0000000000.com/previewsave.php");
echo "<h1>Image Uploaded Successfully!</h1>";
echo '<img src="' . $newname . '" width="150" border="0"><br />'; 
} 
?>

Archived

This topic is now archived and is closed to further replies.

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