Jump to content


Photo

image uploading


  • Please log in to reply
4 replies to this topic

#1 marcs910

marcs910
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 20 June 2006 - 01:38 AM

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:

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

This entry is viewable by the public now
"

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.

Thanks

<?php

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.';
                        break;
                    case 2:
                        print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.';
                        break;
                    case 3:
                        print 'The file was only partially uploaded.';
                        break;
                    case 4:
                        print 'No file was uploaded.';
                        break;
                    case 6:
                        print 'No temporary folder was available.';
                        break;
                    default:
                        print 'A system error occurred.';
                        break;
                } // 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>';
   
   exit();
   
   } 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>';
        
        exit();
        
      }
      
      mysql_close();
      
    }
    
    ?>
    
    <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" />
    </form>
    
    <?php
    
    include ('footer.html');
    
    ?>


#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 20 June 2006 - 02:14 AM

Since you are uploading a file/image, as a start you need to change this...

<form action="admin_new_home.php" method="post">


to this...

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

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

Lite...


all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 marcs910

marcs910
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 20 June 2006 - 02:24 AM

Made that change and still does the same.

THanks so much for the help so far.

#4 marcs910

marcs910
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 21 June 2006 - 12:31 PM

*bimp*

#5 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 21 June 2006 - 01:52 PM

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']}"))
Spreading things out looks like this
if (move_uploaded_file($_FILES['image']['tmp_name'], "../uploads/    {         $_FILES['upload']['name']    }     "))
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.

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users