Jump to content


This topic is now archived and is closed to further replies.


image uploading

Recommended Posts

I've reviewed, added, deleted, reviewed and screamed until I'm on the verge of plucking ear hair.

I've apparantly missed something or somethings in my code. When loading, it immediately goes to:

"[b]Please upload a JPEG or GIF image smaller than 512KB.
Data entered

This entry is viewable by the public now[/b]"

Without any of the image code it inserted all of the data fine.

Could someone please tell me what it is I'm missing?
I havent started the code to insert the temp name into the db yet or view the image. Im just trying to get to the upload file part.



include ('admin_header.html');

  require_once ('mysql_connect.php');

if (isset($_POST['submitted'])) {

// Check for an uploaded file.
    if (isset($_FILES['image'])) {
        // Validate the type. Should be jpeg, jpg, or gif.
        $allowed = array ('image/gif', 'image/jpeg', 'image/jpg', 'image/pjpeg');
        if (in_array($_FILES['upload']['type'], $allowed)) {
            // Move the file over.
            if (move_uploaded_file($_FILES['image']['tmp_name'], "../uploads/{$_FILES['upload']['name']}"))
            echo '<p>The file has been uploaded!</p>';
            } else { // Couldn't move the file over.
                echo '<p><font color="red">The file could not be uploaded because: </b>';
                // Print a message based upon the error.
                switch ($_FILES['upload']['error']) {
                    case 1:
                        print 'The file exceeds the upload_max_filesize setting in php.ini.';
                    case 2:
                        print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.';
                    case 3:
                        print 'The file was only partially uploaded.';
                    case 4:
                        print 'No file was uploaded.';
                    case 6:
                        print 'No temporary folder was available.';
                        print 'A system error occurred.';
                } // End of switch.
                print '</b></font></p>';

            } // End of move... IF.
        } else { // Invalid type.
            echo '<p><font color="red">Please upload a JPEG or GIF image.</font></p>';
            unlink ($_FILES['upload']['tmp_name']); // Delete the file.

    } else { // No file uploaded.
        echo '<p><font color="red">Please upload a JPEG or GIF image smaller than 512KB.</font></p>';
} //End of conditional


   $query = "INSERT INTO homes (category, type, address, location, zip, year, bedroom, bathroom, garage, lotsize, stories, active, price, description, date_entered)
   VALUES ('$category', '$type', '$address', '$location', '$zip', '$year', '$bedroom', '$bathroom', '$garage', '$lotsize', '$stories', '$active', '$price', '$description', NOW())";
   $result = @mysql_query ($query);
   if ($result) {
   echo '<h1 id="mainhead">Data entered</h1>
   <p>This entry is viewable by the public now.</p><p><b /></p>';
   } else {
        echo '<h1 id="mainhead">System Error</h1>
        <p class="error">Your data could not be entered due to a system error.</p>';
        echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>';
    <h2>Enter your data</h2>
    <form action="admin_new_home.php" method="post">
    <p>Category:<input type="text" name="category" size "15" maxlength="15" value="<?php if
    (isset($_POST['category'])) echo$_POST['category']; ?>" /></p>
       <p>Type:<input type="text" name="type" size "15" maxlength="15" value="<?php if
    (isset($_POST['type'])) echo$_POST['type']; ?>" /></p>

    <p>Address:<input type="text" name="address" size "15" maxlength="30" value="<?php if
    (isset($_POST['address'])) echo$_POST['address']; ?>" /></p>
    <p>Location:<input type="text" name="location" size "15" maxlength="15" value="<?php if
    (isset($_POST['location'])) echo$_POST['location']; ?>" /></p>
    <p>Zip Code:<input type="text" name="zip" size "15" maxlength="15" value="<?php if
    (isset($_POST['zip'])) echo$_POST['zip']; ?>" /></p>

    <p>Year:<input type="text" name="year" size "15" maxlength="15" value="<?php if
    (isset($_POST['year'])) echo$_POST['year']; ?>" /></p>
    <p>Bedrooms:<input type="text" name="bedroom" size "15" maxlength="15" value="<?php if
    (isset($_POST['bedroom'])) echo$_POST['bedroom']; ?>" /></p>
    <p>Bathrooms:<input type="text" name="bathroom" size "15" maxlength="15" value="<?php if
    (isset($_POST['bathroom'])) echo$_POST['bathroom']; ?>" /></p>

    <p>Garage:<input type="text" name="garage" size "15" maxlength="15" value="<?php if
    (isset($_POST['garage'])) echo$_POST['garage']; ?>" /></p>
    <p>Lot Size:<input type="text" name="lotsize" size "15" maxlength="15" value="<?php if
    (isset($_POST['lotsize'])) echo$_POST['lotsize']; ?>" /></p>
    <p>Stories:<input type="text" name="stories" size "15" maxlength="15" value="<?php if
    (isset($_POST['stories'])) echo$_POST['stories']; ?>" /></p>

   <p>Active:<input type="text" name="active" size "15" maxlength="15" value="<?php if
   (isset($_POST['active'])) echo$_POST['active']; ?>" /></p>  

    <p>Price:<input type="text" name="price" size "15" maxlength="15" value="<?php if
     (isset($_POST['price'])) echo$_POST['price']; ?>" /></p>
    <p>Description:<input type="text" name="description" size "25" maxlength="100" value="<?php if
    (isset($_POST['description'])) echo$_POST['description']; ?>" /></p>
   <input type="hidden" name="MAX_FILE_SIZE" value="524288">
        <fieldset><legend>Select a JPEG or GIF image to be uploaded:</legend>
        <p><b>File:</b> <input type="file" name="image" /></fieldset></p>

    <p><input type="submit" name="submit" value="Submit" /></p>
    <input type="hidden" name="submitted" value="TRUE" />
    include ('footer.html');

Share this post

Link to post
Share on other sites
Since you are uploading a file/image, as a start you need to change this...

[code]<form action="admin_new_home.php" method="post">[/code]

to this...

[code]<form action="admin_new_home.php" method="post" enctype="multipart/form-data">[/code]

Sorry but am too tired today to review entire script - but that is a DEFINITE change you need to make.


Share this post

Link to post
Share on other sites
I cut and pasted your script to do some 'fine combing'.

This is your original line...
if (move_uploaded_file($_FILES['image']['tmp_name'], "../uploads/{$_FILES['upload']['name']}"))[/code]Spreading things out looks like this
if (move_uploaded_file($_FILES['image']['tmp_name'], "../uploads/    {         $_FILES['upload']['name']    }     "))[/code]A couple of things 'bothered' my eye...

1. the use of braces { } rather than parens ( )

2. no brace { at end of line

Not totally sure if these are the cause.


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.