Simpelt upload script,...
HejJeg har nu længe prøvet at lave et simpelt upload script, men jeg får heletiden fejlmeddelsen : is empty , fejlmeddelsen kommer fra denne del kode :
if($userfile_size <= 0){
die ("$filename is empty");
Det lader til at $filename er en ukendt faktor.
Så langt så godt, jeg har på fornemmelsen at filnen aldrig bliver registreret og sendt til :
function upload_file(){
global $userfile, $userfile_name, $userfile_size, $userfile_type, $archive_dir, $windir;
er der nogen der har en ide til hvordan dette kan løses, her er hele koden :
<?php
include_once("config.php");
checkLoggedIn("yes");
doCSS();
$archive_dir = 'dokumenter';
function upload_form(){
global $PHP_SELF;
?>
<form method="post" enctype="MULTIPART/FORM-DATA" action="<? echo $PHP_SELF ?>">
<input type="hidden" name="action" value="upload">
<input type="file" name="userfile">
<input type="submit" name="action" value="upload">
</form>
<?
}
function upload_file(){
global $userfile, $userfile_name, $userfile_size, $userfile_type, $archive_dir, $windir;
if(isset($windir)){
$userfile = str_replace("\\\\","\\", $userfile);
}
$filename = basename($userfile_name);
if($userfile_size <= 0){
die ("$filename is empty");
}
if(!@copy($_FILES['userfile']['tmp_name'], "$archive_dir/$filename")){
die("Can't copy $userfile_name to $filename");
}
if(isset($windir) && !@unlink($userfile)){
die("Can't delete the file $userfile_name");
}
echo $filename." has been succesfully uploaded.<br>";
echo "Filesize: ".number_format($userfile_size)."<br>";
echo "Filetype: ".$userfile_type."<br>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>KFUM Børkop gruppen</title>
</head>
<body>
<table align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="1" rowspan="3" bgcolor="#005500"></td>
<td height="2" bgcolor="#005500"></td>
<td width="2" rowspan="3" bgcolor="#005500"></td>
</tr>
<tr>
<td height="69" bgcolor="#009966"><div align="center"><img src="images/Top_2.png" width="1000" height="100" /></div></td>
</tr>
<tr>
<td height="2" bgcolor="#005500"></td>
</tr>
<tr>
<td bgcolor="#005500"></td>
<td align="center" valign="top" bgcolor="#009966">
<?
if ($_POST['action'] == 'upload'){
upload_file();
} else {
upload_form();
}
?></td>
<td bgcolor="#005500"></td>
</tr>
<tr>
<td bgcolor="#005500"></td>
<td height="2" bgcolor="#005500"></td>
<td bgcolor="#005500"></td>
</tr>
</table>
</body>
</html>