Avatar billede theguardian Nybegynder
13. februar 2001 - 16:17 Der er 1 løsning

Need help to code :-/

Jeg har et lille opload system som gerne skulle skrive nogle oplysningen i en fil, men selve beskrivelsen bliver ikke skrevet i filen hvorfor ???

Her er koden:

<?php

$my_max_file_size     = \"512000\"; # in bytes
$image_max_width    = \"192\";
$image_max_height    = \"192\";
$the_path        = \"c:\\\\apache\\\\htdocs\\\\opload by me\\\\final upload\\\\\";

$registered_types = array(
                    \"application/x-gzip-compressed\"                     => \".tar.gz, .tgz\",
                    \"application/x-zip-compressed\"                         => \".zip\",
                    \"application/x-tar\"                    => \".tar\",
                    \"image/gif\"                         => \".gif\",
                    \"image/pjpeg\"                        => \".jpg, .jpeg\",
                    \"image/jpeg\"                        => \".jpg, .jpeg\",
                    \"application/octet-stream\"                => \".scx\",
                                        \"application/x-icq\"                                    => \".scm\",
                    ); # these are only a few examples, you can find many more!

$allowed_types = array(\"application/x-icq\",\"application/octet-stream\",\"application/x-zip-compressed\",\"application/x-gzip-compressed\");

# --

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>Opload en bane, og skriv en beskrivelese\";
    print \"\\n<BR>OBS: Baner må max. fylde \" . ($my_max_file_size / 1024) . \"KB\";
    print \"\\n<br><INPUT NAME=\\\"the_file\\\" TYPE=\\\"file\\\" SIZE=\\\"20\\\"><br>\";
        print \"\\n<TEXTAREA COLS=\\\"31\\\" ROWS=\\\"7\\\" WRAP=\\\"PHYSICAL\\\" NAME=\\\"beskrivelse\\\">Her kan du skrive en lille beskrivelse, evt. hvem der har lavet den.</TEXTAREA><br>\";
    print \"\\n<input type=\\\"submit\\\" Value=\\\"Opload\\\">\";
    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 fik ikke oploadede noget!</li>\";

    } else { # check if we are allowed to upload this file_type

        if (!in_array($the_file_type,$allowed_types)) {
            $error .= \"\\n<li>Den type fil du prøver at oploade er ikke tilladt her på server. Typer:\\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>Dit 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 list_files() {

global $the_path;

    $handle = dir($the_path);
    print \"\\n<b>Oploadede filer:</b><br>\";
    while ($file = $handle->read()) {
        if (($file != \".\") && ($file != \"..\")) {
            print \"\\n\" . $file . \"<br>\";
      }
    }
    print \"<hr>\";
}

# --

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>Der gik noget galt, kontakt zephid</b>\");
        } else {
  form(\"<b>Din bane er nu oploadede :-)</b>\");
$file = \"maps.txt\";
$str = \"
<table border=\\\"2\\\" bordercolor=\\\"black\\\" cellspacing=\\\"0\\\" cellpadding=\\\"2\\\">
<tr>
    <td>$beskrivelese</td>
</tr>
<tr>
    <td><center><a href=\\\"baner/$the_file_name\\\" class=\\\"link\\\"></a></center></td>
</tr>
</table><br>
\";

$fp = fopen($file, \"r\");
$arr = file($file);
$res = implode( \"\", $arr);
$res = \"$str$res\";
fclose($fp);

$fp = fopen($file, \"w\");
fputs($fp, $res);
fclose($fp);
        }
    }
} # END upload

# --

############ Start page

print \"<html>\\n<head>\\n<title>Bane opload</title>\\n</head>\\n<body BGCOLOR=\\\"#1f1f1f\\\" TEXT=\\\"#FFFFFF\\\" LINK=\\\"#0000ff\\\" VLINK=\\\"#ff0000\\\" ALINK=\\\"#7f007f\\\">\";

switch($task) {
    case \'upload\':
        upload($the_file);
    break;
    default:
        form();
}

print \"\\n</body>\\n</html>\";

?>
Avatar billede theguardian Nybegynder
16. februar 2001 - 00:25 #1
JEg fandt selv problemmet, så :-)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester