Upload billed med nyhed
HejsaHåber at nogle kan hjælpe mig, med at løse et upload problem. Når jeg laver en nyhed via siden news.add og forsøger at tilknytte et billed til nyheden, gemmer den ikke billedet.
Hvis jeg ellers ligger et billede op via et direkte script, fungere det. Men ikke igennem denne nyhed, hvad har jeg overset?
news.add.php -->
<?php
require('../access/access_config.php');
// Creating option tags with category data
$Res = mysql_query("SELECT id, category FROM news_category ORDER BY category");
$CategoryOptions = "";
while (list($CategoryId,$CategoryTitle) = mysql_fetch_row($Res))
{
$CategoryOptions .= "<option value=\"$CategoryId\">".stripslashes($CategoryTitle)."</option>\n";
}
?>
<html>
<head>
<title></title>
</head>
<body>
<?php include ('../includes/menu.php'); ?>
<form action="news.config.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="referer" value="news.add">
<table border="0" width="100%">
<tr>
<td width="10%">Overskrift</td>
<td width="1%">:</td>
<td width="89%"><input type="text" name="title" size="42"></td>
</tr>
<tr>
<td width="10%">Synops</td>
<td width="1%">:</td>
<td width="89%"><textarea rows="3" name="synopsis" cols="32"></textarea></td>
</tr>
<tr>
<td width="10%"> </td>
<td width="1%"></td>
<td width="89%"></td>
</tr>
<tr>
<td width="10%">Emne/kategori</td>
<td width="1%">:</td>
<td width="89%"><select name="category"><?php echo $CategoryOptions; ?></select></td>
</tr>
<tr>
<td width="10%">Vedhæft billede</td>
<td width="1%">:</td>
<td width="89%"><input type="file" name="image" size="42"></td>
</tr>
<tr>
<td width="10%">Andet billede</td>
<td width="1%">:</td>
<td width="89%"><input type="text" name="standard" size="42"></td>
</tr>
<tr>
<td width="10%"></td>
<td width="1%"></td>
<td width="89%">Indtast filnavnet på billedet du vil bruge<br><a href="images.list.php" target="_blank">Se uploadede billeder</a></td>
</tr>
<tr>
<td width="10%"> </td>
<td width="1%"></td>
<td width="89%"></td>
</tr>
<tr>
<td width="10%">Nyheden</td>
<td width="1%">:</td>
<td width="89%"><textarea rows="11" name="text" cols="32"></textarea></td>
</tr>
<tr>
<td width="10%"> </td>
<td width="1%"></td>
<td width="89%"></td>
</tr>
<tr>
<td width="10%"></td>
<td width="1%"></td>
<td width="89%"><input type="submit" value="Opret nyhed" name="B1">
<input type="reset" value="Slet alt" name="B2">
<input type="hidden" name="ip" value="<?php print $_SERVER['REMOTE_ADDR']; ?>"></td>
</tr>
</table>
</form>
</body>
</html>
news.config.php -->
<?php
include('../access/access_config.php');
if ($_POST['referer'] == 'news.add') {
if ($_FILES['image']['name'] != '') {
$image = time().substr($_FILES['image']['name'],strrpos($_FILES['image']['name'],'.'));
move_uploaded_file($_FILES['image']['tmp_name'], '../../news/images/'.$image);
} elseif ($_POST['standard'] != '') {
$image = $_POST['standard'];
} else {
$image = '';
}
mysql_query("INSERT INTO news (ip, category, date, writer, title, synopsis, text, source, image) VALUES ('".$_POST['ip']."','".$_POST['category']."',NOW(),'".$_POST['writer']."','".$_POST['title']."','".$_POST['synopsis']."','".$_POST['text']."','".$_POST['source ']."','".$_POST['image']."')") or die(mysql_error());
header("Location: news.list.php");
}
if ($_POST['referer'] == 'upload') {
for ($i=0;$i<count($_FILES['file']['name']);$i++) {
if ($_FILES['file']['name'][$i] != '') {
move_uploaded_file($_FILES['file']['tmp_name'][$i], '../../news/images/'.$_FILES['file']['name'][$i]);
}
}
header("Location: images.list.php");
}
?>
