Unidentified
Living the Developer Life...
- Jun 19, 2012
- 144
- 20
I have got it so it posts into the table 'images' but I am struggling to get it to post into the table 'Post'
PHP:
<?php
define ('MAX_FILE_SIZE', 15000 * 50);
if (array_key_exists('upload', $_POST)) {
$n = rand(0, 100);
$rand = $_SESSION['id']*3+1-4+100-$n*8;
$rand1 = $_SESSION['id']*7-4+100-$n*8;
define('UPLOAD_DIR', "avatars/$id/");
$_FILES['image']['name'] = $rand.$rand1.$_FILES['image']['name'];
$file = str_replace(' ', '_', $_FILES['image']['name']);
$permitted = array('image/gif', 'image/jpg', 'image/jpeg', 'image/png');
if (in_array($_FILES['image']['type'], $permitted)
&& $_FILES['image']['size'] > 0
&& $_FILES['image']['size'] <= MAX_FILE_SIZE) {
switch($_FILES['image']['error']) {
case 0:
if (!file_exists(UPLOAD_DIR . $file)) {
$file = str_replace(")", '', $file);
$file = str_replace("(", '', $file);
$success = move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR . $file);
$query = mysql_query("SELECT * FROM `images` WHERE `myid`='".$_SESSION['id']."' LIMIT 1");
$line = mysql_num_rows($query);
mysql_query("INSERT INTO `images` (`myid`,`name`, `path`) VALUES ('".$_SESSION['id']."','".$_POST['name']."', '".UPLOAD_DIR . $file."')");
mysql_query("INSERT INTO `post` (`myid`, `path`) VALUES ('".$_SESSION['id']."', '".UPLOAD_DIR . $file."')");
mysql_free_result($query);
} else {
$result = 'A file of the same name already exists.';
}
if (isset($success)) {
$result = "$file uploaded successfully.";
} else {
$result = "Error uploading $file. Please try again.";
}
break;
case 3:
case 6:
case 7:
case 8:
$result = "Error uploading $file. Please try again.";
break;
case 4:
$result = "You didn't select a file to be uploaded.";
}
} else {
$result = "$file is either too big or not an image.";
}
}
?>