I’ve been browsing Google to find a few tips but couldn’t seem to get a good idea of what the best approach would be:
Basically, just want to upload multiple images via form input, store the image src’s as an array in my database table, and pull these images to display them on a page. The concept behind it is just a basic CMS for myself… to create a new portfolio piece and display images for it.
This is my current code for just uploading a thumbnail and single image:
if(isset($_FILES['fupload'])) {
$filename = addslashes($_FILES['fupload']['name']);
$source = $_FILES['fupload']['tmp_name'];
$target = $path_to_image_directory . $filename;
$name = addslashes($_POST['name']);
$des = addslashes($_POST['description']);
$client = addslashes($_POST['client']);
$src = $path_to_image_directory . $filename;
$thumb_src = $path_to_thumbs_directory . $filename;
// Validates the form input
if(strlen($_POST['description']) < 4)
$error['description'] = '<p class="alert">Please enter a description for your photo. </p>';
if($filename == '' || !preg_match('/[.](jpg)|(gif)|(png)|(jpeg)$/', $filename))
$error['no_file'] = '<p class="alert">Please select an image, dummy! </p>';
// my version of transferring the file from temp to images
if(move_uploaded_file($_FILES['fupload']['tmp_name'], $target)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
// original versin of transferring images from file
if(!$error) {
move_uploaded_file($source, $target);
$q = "INSERT into projects(id,name,description,client,src,thumb_src) VALUES('','$name','$des','$client','$src', '$thumb_src')";
$result = mysql_query($q);
if($result) {
echo "Success! Your file has been uploaded";
} else {
echo "You ****ed up somewhere..";
}
createThumbnail($filename);
} // end preg_match
}
?>
<h1>Add A New Project</h1>
<form enctype="multipart/form-data" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="MAX_FILE_SIZE" value="30000000" />
<p><input type="file" name="fupload" /></p>
<p><label for="name">Project Name:</label></p>
<p><textarea rows="1" cols="50" id="name" name="name"></textarea></p>
<p><label for="client">Client:</label></p>
<p><textarea rows="1" cols="50" id="client" name="client"></textarea></p>
<p><label for="description">Project Description:</label></p>
<p><textarea rows="6" cols="50" id="description" name="description"></textarea></p>
<p><input type="submit" value="Add Project" name="submit" /></p>
</form>
What’s the best approach I should take with this?