Uploading Image Difficulty

I am currently in a class for PHP and MYSQL. My web host is GoDaddy.com (GD) if that helps any, but I am using the most current version of Dreamweaver to write my code and upload it to my website.

The form below is part of the book’s course form. All the information in the form uploads into my database, including the ‘image’ name. However, the actual file (used in conjunction with the input type=“file” id=“image” name=“image”/> part of the form) does not upload or transfer into its final folder position, which is named ‘images’ in the same directory that my ‘index.php’ file resides on my account.

I have tried over a dozen different implementations, even going so far to have an external .php file to handle the image section, to no avail. Each time, the form outputs and uploads successfully minus the image (which gets the ‘else’ response of “Error with Image”. There are no syntax errors, and I have run through it in terms of how it executes, and I do not find a reason as to why it would not execute.

I have contacted GD support and they were not really helpful (even saying that it was better if I could write my code on Linux). In the end they told me what I already knew (to some degree) and that is with my code (somewhere). However, I am unaware as to where exactly the problem is, as I have followed the book instructions.

Any and all assistance is greatly appreciated.

(Note: all information related to my actually database, password etc has been removed due to security concerns)

-----------START OF PHP------------------

Aliens Abducted Me - Report an Abduction

Aliens Abducted Me - Report an Abduction

<?php define('GW_UPLOADPATH', 'images/'); if (isset($_POST['submit'])){ $first_name = $_POST['firstname']; $last_name = $_POST['lastname']; $email = $_POST['email']; $when_it_happened = $_POST['whenithappened']; $how_long = $_POST['howlong']; $how_many = $_POST['howmany']; $alien_description = $_POST['aliendescription']; $what_they_did = $_POST['whattheydid']; $fang_spotted = $_POST['fangspotted']; $other = $_POST['other']; $image = $_FILES['image']['name']; $image_type = $_FILES['image']['type']; $image_size = $_FILES['image']['size']; $image_temp = $_FILES['image']['tmp_name']; $image_error = $_FILES['image']['error']; $output_form = false; if (empty($first_name) && empty($last_name) && empty($email)) { echo 'You MUST enter your First Name.
'; echo 'You MUST enter your Last Name.
'; echo 'You MUST enter your Email Address.
'; $output_form = true; } if (empty($first_name) && (!empty($last_name)) && empty($email)) { echo 'You MUST enter your First Name.
'; echo 'You MUST enter your Email Address.
'; $output_form = true; } if (empty($first_name) && empty($last_name) && (!empty($email))) { echo 'You MUST enter your First Name.
'; echo 'You MUST enter your Last Name.
'; $output_form = true; } if (empty($first_name) && (!empty($last_name)) && (!empty($email))) { echo 'You MUST enter your First Name.
'; $output_form = true; } if ((!empty($first_name)) && empty($last_name) && empty($email)) { echo 'You MUST enter your Last Name.
'; echo 'You MUST enter your Email Address.
'; $output_form = true; } if ((!empty($first_name)) && empty($last_name) && (!empty($email))) { echo 'You MUST enter your Last Name.
'; $output_form = true; } if ((!empty($first_name)) && (!empty($last_name)) && empty($email)) { echo 'You MUST enter your Email Address.
'; $output_form = true; } } else { $output_form = true; } if ($output_form) { ?>

Share your story of alien abduction:

Other Abductee Stories

First name:


Last name:


What is your email address?


When did it happen?


How long were you gone?


How many did you see?


Describe them:


What did they do to you?


Have you seen my dog Fang?

Yes <input id=“fangspotted” name=“fangspotted” type=“radio” value=“Yes” <?php if (isset($_POST['fangspotted']) && $_POST['fangspotted'] == "Yes") echo 'checked="checked"';?>>

No <input id=“fangspotted” name=“fangspotted” type=“radio” value=“No” <?php if (isset($_POST['fangspotted']) && $_POST['fangspotted'] == "No") echo 'checked="checked"';?>>

My abducted dog Fang.

Anything else you want to add?

<?php echo $_POST['other']; ?>

Evidence:



<?php } ?> <?php if ($output_form == false) { $dbc = mysqli_connect('**.**.***.**','****','****','****') or die ('Error connecting to MySQL server.'); $query = "INSERT INTO **** (first_name, last_name, when_it_happened, how_long, " . "how_many, alien_description, what_they_did, fang_spotted, other, email, image) " . "VALUES ('$first_name', '$last_name', '$when_it_happened', '$how_long', '$how_many', " . "'$alien_description', '$what_they_did', '$fang_spotted', '$other', '$email', '$image') "; $result = mysqli_query($dbc, $query) or die ('Error querying database.'); mysqli_close($dbc); echo 'Thanks for submitting the form.
'; echo 'You were abducted ' . $when_it_happened; echo ' and were gone for ' . $how_long . '
'; echo 'Number of aliens: ' . $how_many . '
'; echo 'Describe them: ' . $alien_description . '
'; echo 'The aliens did this: ' . $what_they_did . '
'; echo 'Was Fang there? ' . $fang_spotted . '
'; echo 'Other comments: ' . $other . '
'; echo 'Your email address is ' . $email . '
'; if(is_file($row['image']) && filesize($row['image'])>0) { $target = GW_UPLOADPATH . $image; if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $dbc = mysqli_connect('**.**.***.**','****','****','****') or die ('Error connecting to MySQL server.'); $query = "INSERT INTO **** VALUES (0, '$first_name', '$last_name', '$when_it_happened', '$how_long', '$how_many', " . "'$alien_description', '$what_they_did', '$fang_spotted', '$other', '$email', '$image')"; mysqli_close($dbc, $query); } echo 'Evidence'; } else { echo 'Error with Image Unverified Image
'; } } ?>

return to Home page

--------------------END of PHP-----------------------

How big is the image you tried to upload? PHP has a default max upload size of 2 meg which can be changed in php.ini. Also, make sure you have write permissions on the image directory.

The test image I’m using is 7kb.

And as far as I know, yes, I do have permissions. I can also manually upload images.

Where would I find the write permissions anyhow?

It depends if you’re on a Windows or Linux box.

In Linux, you can CHMOD, whereas in Windows it’s usually file permissions in IIS.

Well, it just so happens there is a new tutorial on image uploads.

Did i mention it was written by yours truly 8) ;D :stuck_out_tongue:

Red :wink:

All my directories are opened to read/write/modify, the whole shabangabang.

Still not working…

I found the answer (quite honestly, it came through a dream).

I had duplicating uploading code, one set for the image, and another set for the rest of the information.

I simply removed the second set, and it worked.

Thanks for the advice and suggestions. Always helps to have another set of eyes.

Sponsor our Newsletter | Privacy Policy | Terms of Service