Create a Web Form for uploading pictures for a high school reunion. The form should have text input fields for the person's name and a description of the image, and a file input field for the image. To accompany each file, create a text file that contains the name and description of the image. Create a separate Web Page that displays the pictures with a caption showing the name and description fields. Make sure the folder has read and write for everyone.
Here is what I have but it isnt working properly:
Code: Select all
<html>
<head>
<body>
<form action="" method="post" enctype="multipart/form-data"name="uploadImage" id="uploadImage">
<p><input type="text" name="name of person" value="name" size="20"/>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" />
<label for="image">Upload image:</label>
<input type="file" name="image" value="name and description" id="image" />
</p>
<p>
<input type="submit" name="upload" id="upload"
value="Upload" />
</p>
</form></body></head></html>
<?php
define ('MAX_FILE_SIZE', 1024 * 50);
if (array_key_exists('upload', $_POST)) {
define('UPLOAD_DIR', '/path/to/images/');
$file = str_replace(' ', '_', $_FILES['image']['name']);
$permitted = array('image/gif', 'image/jpeg', 'image/pjpeg',
'image/png');
if (in_array($_FILES['image']['type'], $permitted)
&& $_FILES['image']['size'] > 0
&& $_FILES['image']['size'] <= MAX_FILE_SIZE) {
switch($_FILES['image']['error']) {
case 0:
if (!file_exists(UPLOAD_DIR . $file)) {
$success =
move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR .
$file);
} else {
$result = 'A file of the same name already exists.';
}
if ($success) {
$result = "$file uploaded successfully.";
} else {
$result = "Error uploading $file. Please try again.";
}
break;
case 3:
case 6:
case 7:
case 8:
$result = "Error uploading $file. Please try again.";
break;
case 4:
$result = "You didn't select a file to be uploaded.";
}
} else {
$result = "$file is either too big or not an image.";
}
}
?>Anyone have any ideas? Any help is greatly appreciated!