Hoi,
Ik ben druk bezig met het maken van een foto album in php dat de foto's opslaat in een database.
Situatie;
Een gebruik geeft aan hoeveel foto's ($num) hij wil uploaden en in welk album ($album_id). Daarna word een pagina weergegeven met $num x een uploadveld. Elk u
ploadveld heeft 2 onderdelen; een foto en een thumbnail -> het fotoveld heet 'photo_'.$i en het thumbveld heet 'thumb_'.$i

Daarna volgt de volgende code;
<?php
$i = 1;
while ($i <= $_POST['num']) {
//if (($HTTP_POST_FILES['photo_'.$i]['size'] == 0) || ($HTTP_POST_FILES['thumb_'.$i]['size'] == 0)) {
// echo $HTTP_POST_FILES['photo_'.$i];
// $error = TRUE;
// $text .= "The file ".$i." or its thumbnail is missing, file will not be uploaded!\n";
//} else {
$temp_photo['file'] = $HTTP_POST_FILES['photo_'.$i];
$temp_thumb['file'] = $HTTP_POST_FILES['thumb_'.$i];
$temp_photo['name'] = $HTTP_POST_FILES['photo_'.$i]['name'];
$temp_thumb['name'] = $HTTP_POST_FILES['thumb_'.$i]['name'];
$temp_photo['type'] = $HTTP_POST_FILES['photo_'.$i]['type'];
$temp_thumb['type'] = $HTTP_POST_FILES['thumb_'.$i]['type'];
$temp_photo['size'] = $HTTP_POST_FILES['photo_'.$i]['size'];
$temp_thumb['size'] = $HTTP_POST_FILES['thumb_'.$i]['size'];
$temp_photo['temp'] = $HTTP_POST_FILES['photo_'.$i]['tmp_name'];
$temp_thumb['temp'] = $HTTP_POST_FILES['thumb_'.$i]['tmp_name'];
if (($temp_photo['size'] > $_SETTINGS['max_photo_size']) || ($temp_thumb['size'] > $_SETTINGS['max_thumb_size'])) {
$error = TRUE;
$text .= "The file (".$i.") ".$temp_photo['name']." or its thumbnail is too big, file will not be uploaded!\n";
} else {
if ((!$temp_photo['type'] == "image/jpg") || (!$temp_thumb['type'] == "image/jpg")) {
$error = TRUE;
$text .= "The file (".$i.") ".$temp_photo['name']." or its thumbnail is not the right type (must be jpg), file will not be uploaded!\n";
} else {
$fp_photo = @fopen($temp_photo['file'],"r");
if (!$fp_photo) {
$error = TRUE;
$text .= "An error ocurred while reading ".$temp_photo['temp'].", file will not be uploaded!\n";
} else {
$fp_thumb = @fopen($temp_thumb['file'],"r");
if (!$fp_thumb) {
$error = TRUE;
$text .= "An error ocurred while reading ".$temp_photo['temp'].", file will not be uploaded!\n";
} else {
$content_photo = fread($fp_photo,filesize($temp_photo['temp']));
$content_thumb = fread($fp_photo,filesize($temp_thumb['temp']));
fclose($fp_photo);
fclose($fp_thumb);

$date_time = date(Y)."-".date(m)."-".date(d)." ".date(H).":".date(i).":".date(s);

$query = "INSERT INTO photo (`photo`, `photo_type`, `photo_length`, `thumb`, `thumb_type`, `thumb_lengt`, `album_id`, `album_order`, `user_id`, `date-time`) VALUES ('".$content_photo."', '".$temp_photo['type']."', '".$temp_photo['size']."', '".$content_thumb."', '".$temp_thumb['type']."', '".$temp_thumb['size']."', '".$_POST['album_id']."', '".$i."', '".$_SESSION['user_id']."', '".$date_time."');";
echo $query;
}
}
}
}
//}
if ($error == TRUE) {
$footer .= "<input name=\"Back\" type=\"button\" class=\"button\" onClick=\"javascript:history.back(-1)\" value=\"&lt; Back\" />\n";
$footer .= "<input name=\"Cancel\" type=\"button\" class=\"button\" onClick=\"javascript:close()\" value=\"Cancel\" />\n";
}

$i++;
}
echo $text;
echo $footer;
?>

Het probleem is alleen dat ik het bestand niet kan bereiken... Het lijkt erop dat er helemaal geen bestand geupload word :S
PS; ik weet het, de query word helemaal niet uitgevoerd, maar ik wil eerst het resultaat zien voordat ik verder ga zitten werken want wie weet zit ik helemaal fout :S
PS2; de error die ik krijg is; The file (1) or its thumbnail is not the right type (must be jpg), file will not be uploaded! Dus dat betekend dat er geen bestand is toch?
Tenzij je geen .jpg bestand genomen hebt.
Nee, het is echt een jpg bestand... Zowel de thumbnail als de foto zelf
<?php
error_reporting(E_ALL)
?>

zet dat is boven aan het script
Ik krijg als error:
Notice: Undefined index: photo_1 in c:\Wamp\www\scandiatrail\v2\fotos\upload.php on line 146
Moet ik het bestand indexeren ofzo?

Reageren