Hej alle udviklere
Jeg har lavet en kode så man kan uploade billeder på min hjemmeside, men den vil kun ligge datar i databasen, den vil ikke billedet op på serveren..
mappen er CHMOD til 777
<?
include("../../db/database.php");
$kat = 1;
$upload_dir = "../upload/";
// CHECK FOR DIR //
if(!is_dir($upload_dir)) mkdir($upload_dir, 0777); // 0700 FREE FOR ALL // -> 0777 WORKAROUND FOR SAFEMOD //
$submit = $_POST['submit'];
if(isset($submit)){
$temp_name = $_FILES['file']['tmp_name'];
$file_name = $_FILES['file']['name'];
$file_type = $_FILES['file']['type'];
$file_size = $_FILES['file']['size'];
$ext = strrchr($file_name, ".");
$file_path = $upload_dir.$file_name;
$max_size = 2000000; // Bytes
if(isset($_POST['file'])) {
} else {
$epoch = time();
$url = $_POST['url'];
if(empty($url)) {
if($file_size == 0){
$text = "Du mangler at vælge en fil";
}
elseif (($ext != ".jpg") && ($ext != ".jpeg") && ($ext != ".png") && ($ext != ".gif"))
{
$text = "Kun billed filer <b>( $ext )</b>";
}
elseif($file_size > $max_size)
{
$text = "Filen er for stor \\n";
}
elseif(move_uploaded_file($temp_name, $file_path))
{
chmod($file_path, 0777);
}
$file_name2 = str_replace(" ", "%20", $file_name);
$url_real = "" .$upload_dirik . "upload/" . $file_name2 . "";
$upload = 1;
$text = "Filen er uploadet";
} else {
$url_real = $url;
$upload = 0;
$text = "Deeplinket er blevet lavet!";
}
mysql_query("INSERT INTO `gallery_billeder` (`navn`, `beskrivelse`, `url`, `epoch`, `kat_id`) VALUES ('$_POST[navn]', '$_POST[beskrivelse]', '$url_real', '$epoch', '$_POST[kat]');") or die(mysql_error());
//echo "" . $text . "";
echo "<body onload=\\"javascript:alert('" . $text . "');\\">";
print "<meta http-equiv=\\"refresh\\" content=\\"0; url=javascript:history.back(-1);\\">";
}
} else {
// FORM //
echo "<form name=\\"form\\" method=\\"post\\" action=\\"billeder/upload.php\\" enctype=\\"multipart/form-data\\">";
echo "Navn:<br>
<input type='text' name='navn' style='width: 244px;' class='text'><br>
Fil:<br>
<INPUT type=file name=\\"file\\" style='width: 244px;' class='text'><br>
Kategori:<br><select size='1' name='kat' style='width: 244px;'>";
$rev = mysql_query("SELECT * FROM `gallery_kat` ORDER BY navn ASC") or die(mysql_error());
while($data32 = mysql_fetch_array($rev))
{
echo "<option value='" . $data32['id'] . "'>" . $data32['navn'] . "</option>";
}
echo "</select> - <a href=\\"javascript:na_show_layer('cat', 0);\\"><font color=\\"#000000\\">Opret ny</font></a><br>
Beskrivelse:<br>
<textarea name='beskrivelse' style='width: 544px; height: 110px;'></textarea>";
echo "<br><br>";
echo "<input type=\\"submit\\" name=\\"submit\\" value=\\"Upload\\">";
echo "</form>";
}
?>
PÅ FORHÅND TAK