Lid |
|
Heb dit gevonden op php.....nl en dit werkt.
Nu heb ik het aangepast en haal ik uit de database de map waar de foto's inkomen. Probleem is dat hij in men select option gewoon de $var weergeeft inplaats van de inhoud.
Aangepaste versie:
<?php
include("../config.php");
$upload_directory = "temp"; // hier word de foto eerst geupload!
$save_dir = $_POST['dir']; // hier word de foto opgeslagen!
$max_uploads = "20"; // max uploads
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(!is_dir($save_dir))
{
mkdir($save_dir);
}
if ($_POST['files'])
{
printf('<form method="post" action="%s" enctype="multipart/form-data">', '?page=admin&link=upload&dir=$save_dir');
for ($i = 1; $i <= $_POST['files']; $i++)
{
printf('<input type="file" name="file_%s" size="100"><br />', $i);
}
printf('<input type="button" onclick="javascript: history.back(-1);" value="Cancel">');
printf('<input type="submit" value="Upload bestanden">');
printf('<input type="hidden" name="history_files" value="%s">', $_POST['files']);
printf('</form>');
}
else
{
printf('<h3>Resultaten:</h3>');
printf('Bestanden geupload naar: %s<br /><br />', $upload_directory);
printf('<table border="1">');
for ($i = 1; $i <= $_POST['history_files']; $i++)
{
$tmp_filename = $_FILES['file_'.$i]['tmp_name'];
$filename = $_FILES['file_'.$i]['name'];
if (move_uploaded_file($tmp_filename, $upload_directory.'/'.$filename))
{
$status = 'Verzonden...';
$up_file = $upload_directory.'/'.$filename;
$srcimage = imagecreatefromjpeg($up_file);
$width = imageSX($srcimage);
$height = imageSY($srcimage);
if($width <= 250 && $height <= 250){
$t_width=$width;
} else {
if ($height < $width){
$t_width = 400;
}
else {
$t_width = 350;
}
}
$newh1= $height / $width;
$newh2= $newh1 * $t_width;
$destimage = imagecreatetruecolor($t_width,$newh2);
imagecopyresampled($destimage,$srcimage,0,0,0,0,$t_width,$newh2,$width,$height);
ob_start();
ImageJPEG($destimage,'',100);
$buffer = ob_get_contents();
ob_end_clean();
$file=$save_dir.'/'.$filename;
$handle = fopen($file, 'ab');
fwrite($handle, $buffer);
fclose($handle);
$delete=$upload_directory.'/'.$filename;
@unlink($delete);?>
<?
}
else
{
$status = 'Fout!';
}
printf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>', $i, ($filename)?$filename:' ', $status);
}
printf('</table>');
}
}
else
{
printf('<form method="post" action="%s">', '?page=admin&link=upload&dir=$save_dir');
printf('Aantal upload velden: ');
printf('<select name="files">');
for ($i = 1; $i <= $max_uploads; $i++)
{
printf('<option value="%1$s">%1$s', $i);
}
printf('</select><br />');
printf('Kies album: ');
printf('<select name="dir">');
$query = mysql_query("SELECT * FROM fotoalbum ORDER BY naam ASC") or die(mysql_error());
while($var = mysql_fetch_object($query)) {
printf('<option value="$var->album_id">$var->$naam</option>', $i);
}
printf('</select> <br />');
printf('<input type="submit" value="Creëer velden">');
printf('</form>');
}
?>
<?php include("../config.php"); $upload_directory = "temp"; // hier word de foto eerst geupload! $save_dir = $_POST['dir']; // hier word de foto opgeslagen! $max_uploads = "20"; // max uploads if ($_SERVER['REQUEST_METHOD'] == 'POST') { { } if ($_POST['files']) { printf('<form method="post" action="%s" enctype="multipart/form-data">', '?page=admin&link=upload&dir=$save_dir'); for ($i = 1; $i <= $_POST['files']; $i++) { printf('<input type="file" name="file_%s" size="100"><br />', $i); } printf('<input type="button" onclick="javascript: history.back(-1);" value="Cancel">'); printf('<input type="submit" value="Upload bestanden">'); printf('<input type="hidden" name="history_files" value="%s">', $_POST['files']); } else { printf('<h3>Resultaten:</h3>'); printf('Bestanden geupload naar: %s<br /><br />', $upload_directory); for ($i = 1; $i <= $_POST['history_files']; $i++) { $tmp_filename = $_FILES['file_'.$i]['tmp_name']; $filename = $_FILES['file_'.$i]['name']; { $status = 'Verzonden...'; $up_file = $upload_directory.'/'.$filename; $srcimage = imagecreatefromjpeg($up_file); $width = imageSX($srcimage); $height = imageSY($srcimage); if($width <= 250 && $height <= 250){ $t_width=$width; } else { if ($height < $width){ $t_width = 400; } else { $t_width = 350; } } $newh1= $height / $width; $newh2= $newh1 * $t_width; $destimage = imagecreatetruecolor($t_width,$newh2); imagecopyresampled($destimage,$srcimage,0,0,0,0,$t_width,$newh2,$width,$height); ImageJPEG($destimage,'',100); $file=$save_dir.'/'.$filename; $handle = fopen($file, 'ab'); $delete=$upload_directory.'/'.$filename; <? } else { $status = 'Fout!'; } printf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>', $i, ($filename)? $filename:' ', $status); } } } else { printf('<form method="post" action="%s">', '?page=admin&link=upload&dir=$save_dir'); printf('Aantal upload velden: '); printf('<select name="files">'); for ($i = 1; $i <= $max_uploads; $i++) { printf('<option value="%1$s">%1$s', $i); } printf('<select name="dir">'); printf('<option value="$var->album_id">$var->$naam</option>', $i); } printf('<input type="submit" value="Creëer velden">'); } ?>
Origineele versie
<?php
$upload_directory = "temp"; // hier word de foto eerst geupload!
$save_dir = "resize"; // hier word de foto opgeslagen!
$max_uploads = "20"; // max uploads
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if ($_POST['files'])
{
printf('<form method="post" action="%s" enctype="multipart/form-data">', '?page=admin&link=upload');
for ($i = 1; $i <= $_POST['files']; $i++)
{
printf('<input type="file" name="file_%s" size="100"><br />', $i);
}
printf('<input type="button" onclick="javascript: history.back(-1);" value="Cancel">');
printf('<input type="submit" value="Upload bestanden">');
printf('<input type="hidden" name="history_files" value="%s">', $_POST['files']);
printf('</form>');
}
else
{
printf('<h3>Resultaten:</h3>');
printf('Bestanden geupload naar: %s<br /><br />', $upload_directory);
printf('<table border="1">');
for ($i = 1; $i <= $_POST['history_files']; $i++)
{
$tmp_filename = $_FILES['file_'.$i]['tmp_name'];
$filename = $_FILES['file_'.$i]['name'];
if (move_uploaded_file($tmp_filename, $upload_directory.'/'.$filename))
{
$status = 'Verzonden...';
$up_file = $upload_directory.'/'.$filename;
$srcimage = imagecreatefromjpeg($up_file);
$width = imageSX($srcimage);
$height = imageSY($srcimage);
if($width <= 250 && $height <= 250){
$t_width=$width;
} else {
if ($height < $width){
$t_width = 400;
}
else {
$t_width = 350;
}
}
$newh1= $height / $width;
$newh2= $newh1 * $t_width;
$destimage = imagecreatetruecolor($t_width,$newh2);
imagecopyresampled($destimage,$srcimage,0,0,0,0,$t_width,$newh2,$width,$height);
ob_start();
ImageJPEG($destimage,'',100);
$buffer = ob_get_contents();
ob_end_clean();
$file=$save_dir.'/'.$filename;
$handle = fopen($file, 'ab');
fwrite($handle, $buffer);
fclose($handle);
$delete=$upload_directory.'/'.$filename;
@unlink($delete);?>
<?
}
else
{
$status = 'Fout!';
}
printf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>', $i, ($filename)?$filename:' ', $status);
}
printf('</table>');
}
}
else
{
printf('<form method="post" action="%s">', '?page=admin&link=upload');
printf('Aantal upload velden: ');
printf('<select name="files">');
for ($i = 1; $i <= $max_uploads; $i++)
{
printf('<option value="%1$s">%1$s', $i);
}
printf('</select> ');
printf('<input type="submit" value="Creëer velden">');
printf('</form>');
}
?>
<?php $upload_directory = "temp"; // hier word de foto eerst geupload! $save_dir = "resize"; // hier word de foto opgeslagen! $max_uploads = "20"; // max uploads if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_POST['files']) { printf('<form method="post" action="%s" enctype="multipart/form-data">', '?page=admin&link=upload'); for ($i = 1; $i <= $_POST['files']; $i++) { printf('<input type="file" name="file_%s" size="100"><br />', $i); } printf('<input type="button" onclick="javascript: history.back(-1);" value="Cancel">'); printf('<input type="submit" value="Upload bestanden">'); printf('<input type="hidden" name="history_files" value="%s">', $_POST['files']); } else { printf('<h3>Resultaten:</h3>'); printf('Bestanden geupload naar: %s<br /><br />', $upload_directory); for ($i = 1; $i <= $_POST['history_files']; $i++) { $tmp_filename = $_FILES['file_'.$i]['tmp_name']; $filename = $_FILES['file_'.$i]['name']; { $status = 'Verzonden...'; $up_file = $upload_directory.'/'.$filename; $srcimage = imagecreatefromjpeg($up_file); $width = imageSX($srcimage); $height = imageSY($srcimage); if($width <= 250 && $height <= 250){ $t_width=$width; } else { if ($height < $width){ $t_width = 400; } else { $t_width = 350; } } $newh1= $height / $width; $newh2= $newh1 * $t_width; $destimage = imagecreatetruecolor($t_width,$newh2); imagecopyresampled($destimage,$srcimage,0,0,0,0,$t_width,$newh2,$width,$height); ImageJPEG($destimage,'',100); $file=$save_dir.'/'.$filename; $handle = fopen($file, 'ab'); $delete=$upload_directory.'/'.$filename; <? } else { $status = 'Fout!'; } printf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>', $i, ($filename)? $filename:' ', $status); } } } else { printf('<form method="post" action="%s">', '?page=admin&link=upload'); printf('Aantal upload velden: '); printf('<select name="files">'); for ($i = 1; $i <= $max_uploads; $i++) { printf('<option value="%1$s">%1$s', $i); } printf('<input type="submit" value="Creëer velden">'); } ?>
|