chrisgocrazyH
22-06-2007, 04:23 AM
Okay look at title
<?php
########## If add download was hit ##########
else if ($_GET['act'] == 'downloads') {
// If form sent
if ($_POST['add']) {
$title = mysql_real_escape_string($_POST['title']);
$description = mysql_real_escape_string($_POST['description']);
$date = date('n/j/y');
$imgUploadPath = $path.basename(''.$title.'_'.$_FILES['img']['name'].'');
$fileUploadPath = $filePath.basename("".$_FILES['files']['name']."");
// Check fields
if (!$title || !$date) { echo '<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'?act=downloads" /> <span style="color: #FF0000">Please fill in all fields.</span>'; }
// Move file
else if (!move_uploaded_file($_FILES['img']['tmp_name'], $imgUploadPath)) { echo '<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'?act=downloads" /> <span style="color: #FF0000">Error uploading the preview image</span>'; echo $path.basename(''.$title.'_'.$_FILES['img']['name'].'');}
else if (!move_uploaded_file($_FILES['files']['tmp_name'], fileUploadPath)) { echo '<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'?act=downloads" /> <span style="color: #FF0000">Error uploading the file</span>'; }
else {
$insert = mysql_query("INSERT INTO `downloads` (id, title, description, url, img, date) VALUES ('', '$title', '$description', '$filePath".$_FILES['name']['files']."', '$path".$title."_".$_FILES['name']['img']."', '$date')") or die ("Error Inserting Download! \n<br />\n" .mysql_error());
echo '<meta http-equiv="refresh" content="2;URL=index.php" /> The download, <b>'.$title.'</b> has been added.';
}
}
// If form not sent
if (!$_POST['add']) { ?>
<!-- Add Download Form -->
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>?act=downloads" title="add_news">
<table width="400" align="center">
<tr>
<td width="72">Title:</td>
<td width="316"><input type="text" name="title" /></td>
</tr>
<tr>
<td>Description:</td>
<td><input name="description" type="text" maxlength="200" /></td>
</tr>
<tr>
<td>Image:</td>
<td><input type="file" name="img" /></td>
</tr>
<tr>
<td>File:</td>
<td><input type="file" name="files" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="add" value="Add" /></td>
</tr>
</table>
</form>
<!-- /Add Download Form -->
<? }
}
?>
<?php
########## If add download was hit ##########
else if ($_GET['act'] == 'downloads') {
// If form sent
if ($_POST['add']) {
$title = mysql_real_escape_string($_POST['title']);
$description = mysql_real_escape_string($_POST['description']);
$date = date('n/j/y');
$imgUploadPath = $path.basename(''.$title.'_'.$_FILES['img']['name'].'');
$fileUploadPath = $filePath.basename("".$_FILES['files']['name']."");
// Check fields
if (!$title || !$date) { echo '<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'?act=downloads" /> <span style="color: #FF0000">Please fill in all fields.</span>'; }
// Move file
else if (!move_uploaded_file($_FILES['img']['tmp_name'], $imgUploadPath)) { echo '<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'?act=downloads" /> <span style="color: #FF0000">Error uploading the preview image</span>'; echo $path.basename(''.$title.'_'.$_FILES['img']['name'].'');}
else if (!move_uploaded_file($_FILES['files']['tmp_name'], fileUploadPath)) { echo '<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'?act=downloads" /> <span style="color: #FF0000">Error uploading the file</span>'; }
else {
$insert = mysql_query("INSERT INTO `downloads` (id, title, description, url, img, date) VALUES ('', '$title', '$description', '$filePath".$_FILES['name']['files']."', '$path".$title."_".$_FILES['name']['img']."', '$date')") or die ("Error Inserting Download! \n<br />\n" .mysql_error());
echo '<meta http-equiv="refresh" content="2;URL=index.php" /> The download, <b>'.$title.'</b> has been added.';
}
}
// If form not sent
if (!$_POST['add']) { ?>
<!-- Add Download Form -->
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>?act=downloads" title="add_news">
<table width="400" align="center">
<tr>
<td width="72">Title:</td>
<td width="316"><input type="text" name="title" /></td>
</tr>
<tr>
<td>Description:</td>
<td><input name="description" type="text" maxlength="200" /></td>
</tr>
<tr>
<td>Image:</td>
<td><input type="file" name="img" /></td>
</tr>
<tr>
<td>File:</td>
<td><input type="file" name="files" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="add" value="Add" /></td>
</tr>
</table>
</form>
<!-- /Add Download Form -->
<? }
}
?>