CHMod, Upload og Absolut sti
Hey.Jeg har et billed upload script som virkede perfekt på Whitehat.
Nu har jeg så selv fået anskaffet en server som kører Windows og ikke Linux/Unix.
3 Ting jeg er i tvivl om:
1: Absolut Sti: Jeg har min Apache Server installeret her: c:\\Webserver\\Apache\\Apache\\htdocs.
Hvad er den absolutte sti så ??
2: CHMod... hvordan virker det på windows ?... jeg har lidt på fornemmeren det er en Unix Only funktion.
3: Andre eventuelle ting der skal ændres:
HER KOMMER SÅ SELVE SCRIPTET :-)
<?
$my_max_file_size = \"256000\"; # in bytes
$image_max_width = \"800\";
$image_max_height = \"780\";
$the_path = \"/billeder/cw\";
$registered_types = array(
\"application/x-gzip-compressed\" => \".tar.gz, .tgz\",
\"application/x-zip-compressed\" => \".zip\",
\"application/x-tar\" => \".tar\",
\"text/plain\" => \".html, .php, .txt, .inc (etc)\",
\"image/bmp\" => \".bmp, .ico\",
\"image/gif\" => \".gif\",
\"image/pjpeg\" => \".jpg, .jpeg\",
\"image/jpeg\" => \".jpg, .jpeg\",
\"application/x-shockwave-flash\" => \".swf\",
\"application/msword\" => \".doc\",
\"application/vnd.ms-excel\" => \".xls\",
\"application/octet-stream\" => \".exe, .fla (etc)\"
); # these are only a few examples, you can find many more!
$allowed_types = array(\"image/bmp\",\"image/gif\",\"image/pjpeg\",\"image/jpeg\");
# --
function form($error=false) {
global $PHP_SELF,$my_max_file_size;
if ($error) print $error . \"<br><br>\";
print \"\\n<form ENCTYPE=\\\"multipart/form-data\\\" action=\\\"\" . $PHP_SELF . \"\\\" method=\\\"post\\\">\";
print \"\\n<INPUT TYPE=\\\"hidden\\\" name=\\\"MAX_FILE_SIZE\\\" value=\\\"\" . $my_max_file_size . \"\\\">\";
print \"\\n<INPUT TYPE=\\\"hidden\\\" name=\\\"task\\\" value=\\\"upload\\\">\";
print \"\\n<P>Upload et CW billed\";
print \"\\n<BR>Filens maksimum størrelse \" . ($my_max_file_size / 1024) . \"KB\";
print \"\\n<br><INPUT NAME=\\\"the_file\\\" TYPE=\\\"file\\\" SIZE=\\\"35\\\"><br>\";
print \"\\n<input type=\\\"submit\\\" Value=\\\"Upload\\\">\";
print \"\\n</form>\";
} # END form
# --
if (!ereg(\"^4\",phpversion())) {
function in_array($needle,$haystack) { # we have this function in PHP4, so for you PHP3 people
for ($i=0; $i < count($haystack); $i++) {
if ($haystack[$i] == $needle) {
return true;
}
}
}
}
# --
function validate_upload($the_file) {
global $my_max_file_size, $image_max_width, $image_max_height,$allowed_types,$the_file_type,$registered_types;
$start_error = \"\\n<b>Fejl:</b>\\n<ul>\";
if ($the_file == \"none\") { # do we even have a file?
$error .= \"\\n<li>Du uploadede ikke noget!</li>\";
} else { # check if we are allowed to upload this file_type
if (!in_array($the_file_type,$allowed_types)) {
$error .= \"\\n<li>Du har prøvet at uploadede en ulovlig filtype, du må kun uploade:\\n<ul>\";
while ($type = current($allowed_types)) {
$error .= \"\\n<li>\" . $registered_types[$type] . \" (\" . $type . \")</li>\";
next($allowed_types);
}
$error .= \"\\n</ul>\";
}
if (ereg(\"image\",$the_file_type) && (in_array($the_file_type,$allowed_types))) {
$size = GetImageSize($the_file);
list($foo,$width,$bar,$height) = explode(\"\\\"\",$size[3]);
if ($width > $image_max_width) {
$error .= \"\\n<li>Det billede må ikke være bredere end \" . $image_max_width . \" Pixels</li>\";
}
if ($height > $image_max_height) {
$error .= \"\\n<li>Dit billede må ikke være højere end \" . $image_max_height . \" Pixels</li>\";
}
}
if ($error) {
$error = $start_error . $error . \"\\n</ul>\";
return $error;
} else {
return false;
}
}
} # END validate_upload
# --
# --
function upload($the_file) {
global $the_path,$the_file_name;
$error = validate_upload($the_file);
if ($error) {
form($error);
} else { # cool, we can continue
if (!@copy($the_file, $the_path . \"/\" . $the_file_name)) {
form(\"\\n<b>Speciel fejl... kontakt webmasteren</b>\");
} else {
form();
}
}
} # END upload
?>
<?
switch($task) {
case \'upload\':
upload($the_file);
break;
default:
form();
}
?>