I'm working on my first file upload form and got the upload script
from a tutorial. It's telling me that I cannot redeclare
is_uploaded_file, though and I'm not sure what to do.

Here is the form:
        <form id="Upload" action="addarticle3.php"
enctype="multipart/form-data" method="post">
            <input type="hidden" name="MAX_FILE_SIZE" value="3000" />
            <input id="userfile" type="file" name="userfile">
            <p><input id="submit" type="submit" name="submit"
value="Upload"></p>
            </form> 

Here is the script:
<!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=utf-8" />

                <title>Uploading...</title>
            <link href="../styles.css" rel="stylesheet" type="text/css" />
</head>

        <body>
                <p><strong>UPLOADING IMAGE</strong>
        <?
                        if($userfile=="none")
                        {
                        print 'Problem: no file uploaded.';
                        exit;
                        }
                        
                        $upfile = 
"../../../pulpistaken/articleimg/".$userfile_name;
                        
                        if(!copy($userfile, $upfile))
                        {
                        print 'Problem: Could not move file into directory.';
                        exit;
                        }
                        
                        print 'File uploaded successfully<br><br>';
                        $fp = fopen($upfile, "r");
                        $contents = fread($fp, filesize ($upfile));
                        fclose ($fp);
                        
                        $contents = strip_tags($contents);
                        $fp = fopen($upfile, "w");
                        fwrite($fp, $contents);
                        fclose($fp);
                        
                        print 'Preview of uploaded file contents:<br><hr>';
                        echo $contents;
                        echo '<br><hr>';
                        
                ?>

</body>

</html>
<?
function is_uploaded_file($filename)
{
        if(!$tmp_file = get_cfg_var('upload_temp_dir'))
        {
        $tmp_file = dirname(tempnam('', ''));
        }
        
        $tmp_file .= '/' . basename($filename);
        
        return (ereg_replace('+', '/', $tmp_file) == $filename);
}
?>

Here is the error:
Fatal error: Cannot redeclare is_uploaded_file() in
/home1/pulpista/public_html/admin/pulp/articles/addarticle3.php on line 59

What am I doing wrong?

Reply via email to