0

Hello could somebody please tell me why my image upload form is not working? after rigorous testing I can not seem to get the files to my uploaded images folder on the server. I keep getting a max file size error even though I have increased the file size allowed hugely.

Thanks again

<?php

// filename: upload.form.php

// first let's set some variables

// make a note of the current working directory relative to root.
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

// make a note of the location of the upload handler
$uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'multiple.upload.processor.php';

// set a max file size for the html upload form
$max_file_size = 30000; // size in bytes

// now echo the html page
?>


<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

    <link rel="stylesheet" type="text/css" href="stylesheet.css">

    <title>Upload form</title>

</head>

<body id="body">

<form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post">

    <h1>
        Sell-A-Car
    </h1>

    <p>
        <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">
    </p>

    <p>
        <label for="file1">Item Image 1:</label>
        <input id="file1" type="file" name="file[]">
    </p>

    <p>
        <label for="file2">Item image 2:</label>
         <input id="file2" type="file" name="file[]">
    </p>

    <p>
        <label for="file3">Item image 3:</label>
        <input id="file3" type="file" name="file[]">
    </p>

    <p>
        <label for="submit">Press to...</label>
        <input id="submit" type="submit" name="submit" value="SELL IT!">
    </p>

</form>


</body>

</html>

second php file is

<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 100000) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>
user3503682
  • 27
  • 1
  • 7

1 Answers1

2

The file size error refers to your PHP configuration. If you're on a shared hosting and can not modify your php.ini please try the following:

Add these lines in the head of your PHP script

ini_set("post_max_size","64M");
ini_set("upload_max_filesize","64M");

If that doesn't work, create a .htaccess file in the main folder of your application and add

php_value    upload_max_filesize    64M
php_value    post_max_size    64M
Andrea Olivato
  • 2,450
  • 1
  • 18
  • 30