Question

I am running a XAMPP server on my computer. The maximum file size I've uploaded is 24.3kb. My server fails to upload a 78kb file. I know because I get an empty $_FILES['file']['tmp_name'] and an error when attempting to move the file.

I went into php.ini and changed the two variables: upload_max_filesize = 2M and post_max_size = 8M, both to over 100, although it should have worked at 2megabytes and 8 megabytes. Still no success.

I am a little new to php but I did enable all logs and I tried to check error logs but the only one with relevant information was the php error log and the only error I see is 'undefined index in file path/tp/myfile.php on line 13'. Any other error logs I should check?

I looked at a lot of forums and threads and I can't find why mine is not working.

[EDIT] I do have the right encryption type. (I DID after all get one image to upload). enctype="multipart/form-data

[EDIT2] My php script: Just incase your curious, this is an exercise in 'Head First php mysql'

<?php
if(isset($_POST['submit'])){
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $score = $_POST['score'];
    $screenshot = $_FILES['screenshot']['name'];
    $target_directory = "images/$screenshot";
    $tmp_directory = $_FILES['screenshot']['tmp_name'];

    echo "echoing" . $tmp_directory;

    move_uploaded_file($tmp_directory, $target_directory) or die("Failed to move");

$db = "guitarwars";
$table = "highscoretable";

$dbc = mysqli_connect(privateinfor) or die("Failed to connect to server");
mysqli_select_db($dbc, $db) or die("Failed to select database");

$query = "INSERT INTO $table VALUES(0, NOW(), '$first_name', '$last_name', '$score', '$screenshot')";

//mysqli_query($dbc, $query) or die("Failed to query database");

}else{

?>

<html>
    <head>
        <style type="text/css">
            .container {
                width: 100%;
            }
            .container label{
            }
        </style>

    </head>
    <body>
    <h1>Guitar Wars - Add Your High Score</h1>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
        <div class="container">
        <input type="hidden" name="MAX_FILE_SIZE" value="32768" enctype="multipart/form-data"/>
        <label for="first_name">First Name:</label> 
        <input type="text" size="32" maxlength="32" value="<?php echo $first_name; ?>" placeholder="First Name" id="first_name" name="first_name"/>
        <label for="last_name">Last Name:</label> 
        <input type="text" size="32" maxlength="32" value="<?php echo $last_name; ?>" placeholder="Last Name" id="last_name" name="last_name"/></br>
        <label for="score">Score:</label> 
        <input type="text" size="11" maxlength="11" placeholder="Enter score" value="<?php echo $score; ?>" id="score" name="score"/></br>
        <label for="screenshot">Screenshot:</label> 
        <input type="file" id="screenshot" name="screenshot"/></br>
        <input type="submit" name="submit" value="submit" />
        </div>
    </form>
    </body>
</html>
<?php
    }
?>
Was it helpful?

Solution

You also need to change the memory_limit

memory_limit = value
upload_max_filesize = value
post_max_size = value
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top