Here's the dilema....

I have a site, and I want users to be able to submit some information to a database... so for example

Title: ____
Description: ____
PHP Image Upload: Ajax?
[Submit Button]


I don't want to use sessions, or anything of that matter if at all possible, because there's no need to log anything or store information about any of this, submissions are from anonymous visitors...

The thing I don't know how to do, is the upload. I can EASILY make a form, have it submit, and post data to a MySQL table, but how do I do the image upload so that the database knows where the image went, and can post that in the table too...?

I want it to all be done in one go, unless somehow I have them upload the image on a "next" page, but i don't know how I would then verify which image was for what "posting". I need the image to be put in the db with that other info. Just the relative URL to where it was uploaded, as it will be displayed on the site.

hopefully someone understands and can help me out, I need suggestions or preferably code examples on how to do this. Thanks alot guys.

Very simple.

On your form tag and this enctype="mulitpart/form-data"

add to your form <input type="file" name="image" />

On your posting page

// You get the image using this
$imageTMP = $_FILES['image']['tmp_name'];
move_uploaded_file($imageTMP, 'YOUR UPLOAD DIR'.$_FILES['image']['name']);
$imageName = $_FILES['image']['name']
// Insert image name into database

:)

This article has been dead for over six months. Start a new discussion instead.