Hi there,
I've found quite a nice flash / javascript / php based multiple image uploader called FancyUpload.
http://digitarald.de/project/fancyupload/
I've got it working fine, however i need to be able to insert the data into a database
Below is my database structure:
photo_ref
event_ref
photo_thumb
heat
Basically i want to be able to populate the database. because at the moment the script only put the images on the webspace.
So for example if i upload 5 images the database should look like the following:
photo_ref: 1, 2, 3, 4, 5 (auto increment)
event_ref: 1, 1, 1, 1, 1
photo_thumb: image_1.jpg, image_2.jpg, image_3.jpg, etc
heat: test heat, etc
I also want to be able to rename the original file name so that it matches what goes into the database, so image_1_test_heat.jpg. something along the lines of that.
I've managed to do this with my own script but that involves having 5 seperate input files, not the one that fancyupload is using.
If anyone can point me in the right direction i should be able to crack it myself! (Hopefully).
Cheers,
Dan
below is my code for uploading the image:
<?php
include("JSON.php");
$result = array();
if (isset($_FILES['photoupload']) )
{
$file = $_FILES['photoupload']['tmp_name'];
$error = false;
$size = false;
if (!is_uploaded_file($file) || ($_FILES['photoupload']['size'] > 2 * 1024 * 1024) )
{
$error = 'Please upload only files smaller than 2Mb!';
}
if (!$error && !($size = @getimagesize($file) ) )
{
$error = 'Please upload only images, no other files are supported.';
}
if (!$error && !in_array($size[2], array(1, 2, 3, 7, 8) ) )
{
$error = 'Please upload only images of type JPEG.';
}
if (!$error && ($size[0] < 25) || ($size[1] < 25))
{
$error = 'Please upload an image bigger than 25px.';
}
else {
move_uploaded_file($_FILES['photoupload']['tmp_name'], "uploadedfiles/".$_FILES['photoupload']['name']);
}
$addr = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$log = fopen('script.log', 'a');
fputs($log, ($error ? 'FAILED' : 'SUCCESS') . ' - ' . preg_replace('/^[^.]+/', '***', $addr) . ": {$_FILES['photoupload']['name']} - {$_FILES['photoupload']['size']} byte\n" );
fclose($log);
if ($error)
{
$result['result'] = 'failed';
$result['error'] = $error;
}
else
{
$result['result'] = 'success';
$result['size'] = "Uploaded an image ({$size['mime']}) with {$size[0]}px/{$size[1]}px.";
}
}
else
{
$result['result'] = 'error';
$result['error'] = 'Missing file or internal error!';
}
if (!headers_sent() )
{
header('Content-type: application/json');
}
echo json_encode($result);
?>