So I am creating a CMS for a friend of mine's website and am at the stage where they are adding "events" to their database of events. The fields required are the following:
1) Title of Event
2) Description
3) Date
4) Author (who entered the event)
5) Image Relating to the Event
The first 4 are easy, but the 5th I'm having trouble with.
I start off the process when they reach the "Insert Event" tab (the CMS is all one page with <div>s being hidden and shown depending on what needs to be seen) by asking them to upload an image:
<div id="uploadEventImage">
<form action="include/events/uploadEventImage.php" method="post" id="uploadEventImageForm" enctype="multipart/form-data">
<label for="Upload Image">Upload Image</label>
<p><input type="file" name="uploadImage" value="" /></p>
<label for="Image Submission">Upload It!</label>
<p><input type="submit" name="uploadEventImage" /></p>
</form>
</div>
This form is submitted using jQuery's Form plugin which makes the server request an AJAX request. When the AJAX request is complete I hide the "uploadEventImage" <div>, which holds the form they just submitted to. Next, I show the following <div>:
<div id="uploadEventInfo">
<form action="include/events/insertEvent.php" method="post" id="insertEventForm" enctype="multipart/form-data">
<label for="Title">Title of Event</label>
<p><input type="text" name="Title" value="" /></p>
<label for="Body">Description of Event</label>
<p><input type="text" name="Body" value="" /></p>
<label for="Date">Date of Event</label>
<p><input type="text" name="Date" value="" /></p>
<label for="Author">Author for This Event</label>
<p><input type="text" name="Author" value="" /></p>
<label for="Image">Image for The Event</label>
<p><input type="text" name="Image" /></p>
<label for="Submit">Insert New Event</label>
<p><input type="image" src="images/insertEventButton.gif" name="Submit" /></p>
</form>
</div> <!-- End uploadEventInfo -->
What I need is to somehow have the first script called "send back" the FULL PATH to the uploaded image. So I can have that link be inserted into the value of the "Image" <input> tag of the "insertEventForm" form. These values as a whole are entered into a single table in a database which is queried by the main website, which is in Flash, so I can't really change it up to make it easier.
The PHP script for the upload is pretty standard:
$uploaddir = '../../images/events/';
$uploadfile = $uploaddir . basename($_FILES['uploadImage']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['uploadImage']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
Directly from PHP.net's site. Obviously nothing is actually displayed back because the <div> where the script was called from is eventually hidden after the successful AJAX request.
So back to the question, how do I "return" the FULL PATH of the image after the script completes?
Thanks!