Jag har gjort ett uppladdnings script i php där man kan ladda upp 4 stycken bilder i taget. Problemet är att om man ska ladda upp kanske 300 bilder så tar det lång tid.
Det jag undrar över är om det går att markera alla bilder och sedan ladda upp dem, istället för att välja en bild i taget. Hoppas ni förstår vad jag menar och jag är tacksam för svar.
Tryck "Browse files" och välj 1 eller 100 bilder, så laddas dom upp. Kan vara lite trixig att få igång, men jag kör den i ett antal projekt och den funkar riktigt bra.
Har du som på Facebook, att man kan ladda upp fler bilder samtidigt? Min kollega och jag försöker få samma funktion till ett community. Även omvandla varje bild till en miniatyr av 250x250px. Vi kör PHP och jQuery men har inte kommit så speciellt långt med detta :/
Facebook använder en javaapplikation, samma som t.ex. Extrafilm använder. Nu kan inte namnet på den men eftersom dom ser identiska ut så skulle jag tro att det är en applet man kan köpa. Prova att Googla....
@streetrobban: Det är tyvärr inte vad jag söker, jag har redan ett uppladdningsscript där man kan ladda upp flera bilder i taget med hjälp av flera file inputs. Det jag söker är ett sätt att ladda upp flera filer samtidigt genom att markera dem.
Jag har problem med att få den att ladda upp filerna, eller den laddar upp filerna men jag får fel meddelandet:
An error occured:
Warning: md5_file(/customers/haningetaekwondo.se/haningetaekwondo.se/tmp/phpjIqnbe) [function.md5-file]: failed to open stream: No such file or directory in /customers/haningetaekwondo.se/haningetaekwondo.se/httpd.www/admin/test/server/script.php on line 124
{"status":"1","name":"Koala.jpg","hash":false}
Eftersom jag fortfarande är lite osäker på vad koden gör och inte riktigt vet vilken kod jag ska posta så postar jag hela koden:
<?php
/**
* Swiff.Uploader Example Backend
*
* This file represents a simple logging, validation and output.
* *
* WARNING: If you really copy these lines in your backend without
* any modification, there is something seriously wrong! Drop me a line
* and I can give you a good rate for fancy and customised installation.
*
* No showcase represents 100% an actual real world file handling,
* you need to move and process the file in your own code!
* Just like you would do it with other uploaded files, nothing
* special.
*
* @license MIT License
*
* @author Harald Kirschner <mail [at] digitarald [dot] de>
* @copyright Authors
*
*/
/**
* Only needed if you have a logged in user, see option appendCookieData,
* which adds session id and other available cookies to the sent data.
*
* session_id($_POST['SID']); // whatever your session name is, adapt that!
* session_start();
*/
// Request log
/**
* You don't need to log, this is just for the showcase. Better remove
* those lines for production since the log contains detailed file
* information.
*/
$result = array();
$result['time'] = date('r');
$result['addr'] = substr_replace(gethostbyaddr($_SERVER['REMOTE_ADDR']), '******', 0, 6);
$result['agent'] = $_SERVER['HTTP_USER_AGENT'];
if (count($_GET)) {
$result['get'] = $_GET;
}
if (count($_POST)) {
$result['post'] = $_POST;
}
if (count($_FILES)) {
$result['files'] = $_FILES;
}
// we kill an old file to keep the size small
if (file_exists('script.log') && filesize('script.log') > 102400) {
unlink('script.log');
}
$log = @fopen('script.log', 'a');
if ($log) {
fputs($log, print_r($result, true) . "\n---\n");
fclose($log);
}
// Validation
$error = false;
if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
$error = 'Invalid Upload';
}
/**
* You would add more validation, checking image type or user rights.
*/
if (!$error && $_FILES['Filedata']['size'] > 2 * 1024 * 1024)
{
$error = 'Please upload only files smaller than 2Mb!';
}
if (!$error && !($size = @getimagesize($_FILES['Filedata']['tmp_name']) ) )
{
$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, GIF or PNG.';
}
if (!$error && ($size[0] < 25) || ($size[1] < 25))
{
$error = 'Please upload an image bigger than 25px.';
}
// Processing
move_uploaded_file($_FILES['Filedata']['tmp_name'], '../uploads/' . $_FILES['Filedata']['name']);
$return['src'] = '/uploads/' . $_FILES['Filedata']['name'];
if ($error) {
$return = array(
'status' => '0',
'error' => $error
);
} else {
$return = array(
'status' => '1',
'name' => $_FILES['Filedata']['name']
);
// Our processing, we get a hash value from the file
$return['hash'] = md5_file($_FILES['Filedata']['tmp_name']);
// ... and if available, we get image data
$info = @getimagesize($_FILES['Filedata']['tmp_name']);
if ($info) {
$return['width'] = $info[0];
$return['height'] = $info[1];
$return['mime'] = $info['mime'];
}
}
// Output
/**
* Again, a demo case. We can switch here, for different showcases
* between different formats. You can also return plain data, like an URL
* or whatever you want.
*
* The Content-type headers are uncommented, since Flash doesn't care for them
* anyway. This way also the IFrame-based uploader sees the content.
*/
if (isset($_REQUEST['response']) && $_REQUEST['response'] == 'xml') {
// header('Content-type: text/xml');
// Really dirty, use DOM and CDATA section!
echo '<response>';
foreach ($return as $key => $value) {
echo "<$key><![CDATA[$value]]></$key>";
}
echo '</response>';
} else {
// header('Content-type: application/json');
echo json_encode($return);
}
?>
../uploads/ är mappen jag vill att filerna ska hamna i.
Det där är bara exempelkoden, just raden md5_file() används bara i demosyfte för att skriva ut filens md5 summa, att det inte funkar för dig kan t.ex. bero på du sparar filen på fel ställe eller något sånt. Har du t.ex. kollat så att du kan skriva i katalogen där du vill ladda upp filerna?
Hur som helst, testa att ta bort raden och se vad som händer.