i have the following php. the script gives me an error telling me that i have not selected a file to upload even when i have done so. if i try to access the $_FILES['minuteFile']['tmp_name'] i don't get anything but the $_FILES['minuteFile']['name'] would be having some. what could be the cause of the $_FILES['minuteFile']['tmp_name'] not being accessible.

<?php
    require_once 'includes/core.php';

    if ( isset( $_POST['submitted'] ) ) { // form submitted
        $errors = array(); // initialize $errors to an empty array
        $minute = new Minute(); // create a new instance of the Minute class

        // validation for the minute file
        if ( is_uploaded_file( $_FILES['minuteFile']['tmp_name'] ) ) { // a file has been selected for uploading
            if ( ( $_FILES['minuteFile']['type'] == 'application/pdf' ) ) { // file is a .pdf file
                $name = $_FILES['minuteFIle']['name'];
                if ( file_exists( ARCHIVE . DS . $name ) ) { // file already exists in archives folder
                    $errors[] = 'Upload a different file. File already exists on server.';
                    unlink( $_FILES['minuteFile']['tmp_name'] ); // delete file from temporary location
                } elseif ( !file_exists( ARCHIVE . DS . $name ) ) { // file doesn't exist in archives folder
                    // move the selected file from the temporary folder to the archives folder
                    $moveResult = move_uploaded_file( $_FILES['minuteFile']['tmp_name'], ARCHIVE . DS . $name );
                    if ( $moveResult ) { // move operation was successful
                        $minute = $name;
                    } elseif ( !$moveResult ) { // move operation not successful
                        unlink( $_FILES['minuteFile']['type'] ); // delete file from temporary location
                    }
                }
            }
        } else { // not file selected for upload
            $errors[] = 'Please select a file to upload.';
        }
    }
?>
<!DOCTYPE html>
    <head>
        <title>Harare City Council: Add New Minutes</title>
        <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
    </head>
    <body>
        <div align="center">
            <div id="content">
                <h2>New Minutes Details</h2>
                <?php
                    if ( isset( $errors ) && is_array( $errors ) ) {
                        echo '<ul>';
                        foreach( $errors as $error ) {
                            echo '<li class="error">' . $error . '</li>';
                        }
                        echo '</ul>';
                    }
                ?>
                <form action="" method="post" enctype="multipart/form-data">
                    <table cellpadding="3" cellspacing="3">
                        <tr>
                            <td class="datalabel">Title:</td>
                            <td><input type="text" name="txtMinutesTitle" size="30" maxlength="60" value="<?php if ( isset( $_POST['txtMinutesTitle'] ) ) echo $_POST['txtMinutesTitle']; ?>" /></td>
                        </tr>
                        <tr>
                            <td class="datalabel">File(.pdf):</td>
                            <td><input type="file" name="minuteFile" /></td>
                        </tr>
                        <tr>
                            <td colspan="2" align="right">
                                <input type="submit" name="submitted" value="Save" />&nbsp;&nbsp;
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </body>
</html>

Recommended Answers

All 6 Replies

Member Avatar for diafol

I'd suggest that you add a few echoes in key places to trace the path your code takes.

i added the followig code on line 7

echo $_FILES['minuteFile']['tmp_name'] . " " . $_FILES['minuteFile']['name'] . " " . $_FILES['minuteFile']['type'];

it's still producing inconsistent results. at times the temporary location is displayed but not always

Member Avatar for diafol

Try print_r($_FILES) on line7

At other places just echo "echo1" etc to show which branch of the conditionals you're following

Array ( [minuteFile] => Array ( [name] => LadiesFashion_2.pdf [type] => [tmp_name] => [error] => 1 [size] => 0 ) ) 1

that's the output i got but i had selected a file

problem solved. thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.