hallo,
ik heb een upload script van het internet geplukt.
en ik wou vragen hoe of ik hier meerder files in kan laten uploaden:
functie.php
<?php
// Image converter & uploader
function insertImage($upload, $dir, $q, $width, $height) {
/* Insert array image system
Format for array : ResizeWidth, ResizeHeight, ResizeQuality, FolderLocation
Example 1 : $image_set[] = array ('320', '240', '95', 'upload/images/resize/');
Example 1 : $image_set[] = array ('240', '180', '90', 'upload/images/thumb/');
Special format : Use 'set' for no resize. (normal upload)
Example : $image_set[] = array ('set', 'set', 'set', 'upload/images/');
NOTE : Quality settings are 1-100. FolderLocation should end with a slash '/'.
*/
// Fill this array with thumbnail settings
$image_set = array ();
@mkdir("images/".$_POST["naam"]."",0777) or die("
Er bestaan al een directory met die titel, dus tevens ook een nieuws bericht met die titel!<br>
<a href=\"javascript:history.back(-1)\">Keer terug</a>, en verzin een andere titel");
@mkdir("images/".$_POST["naam"]."/ori",0777);
@mkdir("images/".$_POST["naam"]."/thumb",0777);
$setdir = $dir;
$image_set[] = array ('set', 'set', 'set', 'images/'.$setdir.'/ori/');
$image_set[] = array (''.$width.'', ''.$height.'', ''.$q.'', 'images/'.$setdir.'/');
$image_set[] = array ('60', '30', '95', 'images/'.$setdir.'/thumb/');
// Retrieve variables of the image file
$file_type = $_FILES[$upload]['type'];
$file_temp = $_FILES[$upload]['tmp_name'];
$file_name = str_replace(array ("\\", "'", " "), array ("", "", "_"), strtolower($_FILES[$upload]['name']));
$file_ext = end(explode('.',$file_name));
// Array of ID numbers (only used if you enable MySQL option
$image_array = array();
// Check for image type (pjpeg & x-png for IE upload bug)
if (((($file_type == 'image/jpeg') or ($file_type == 'image/pjpeg')) and (($file_ext == 'jpg') or ($file_ext == 'jpeg'))) or
((($file_type == 'image/png') or ($file_type == 'image/x-png')) and ($file_ext == 'png')) or
(($file_type == 'image/gif') and ($file_ext == 'gif'))) {
// Loops image thumbnail function for each row automatically
if ($image_set_list = current($image_set)) {
do {
// Load settings from array row
$resize_width = current($image_set_list);
$resize_height = next($image_set_list);
$resize_quality = next($image_set_list);
$file_path = next($image_set_list);
// Name check & rename if exists
$file_path_check = $file_path.$file_name;
$file_name_check = $file_name;
for ($i=0; (file_exists($file_path_check)); $i++) {
$file_name_check = $i."_".$file_name;
$file_path_check = $file_path.$file_name_check;
}
$file_name = $file_name_check;
$file_path = $file_path_check;
if ($resize_quality == "set") {
copy($file_temp, $file_path);
} else {
// Different function for each type
if ((($file_type == 'image/jpeg') or ($file_type == 'image/pjpeg')) and (($file_ext == 'jpg') or ($file_ext == 'jpeg'))) {
$picture_org = imagecreatefromjpeg($file_temp);
} else if ((($file_type == 'image/png') or ($file_type == 'image/x-png')) and ($file_ext == 'png')) {
$picture_org = imagecreatefrompng($file_temp);
} else if (($file_type == 'image/gif') and ($file_ext == 'gif')) {
$picture_org = imagecreatefromgif($file_temp);
}
// Retrieve original image size
$picture_org_w = imagesx($picture_org);
$picture_org_h = imagesy($picture_org);
// Check aspect ratio of thumbnail and original picture
$ratio_org = $picture_org_w / $picture_org_h;
$ratio_new = $resize_width / $resize_height;
// Calculate margin space to keep aspect ratio correct
if ($ratio_new >= $ratio_org) {
$picture_margin_h = ($picture_org_h - ($picture_org_w / $ratio_new));
$picture_margin_w = 0;
} else {
$picture_margin_w = ($picture_org_w - ($picture_org_h * $ratio_new));
$picture_margin_h = 0;
}
// Create thumbnail image
$picture_new=imagecreatetruecolor($resize_width, $resize_height);
imagecopyresized($picture_new, $picture_org, 0, 0, $picture_margin_w/2, $picture_margin_h/2, $resize_width, $resize_height, $picture_org_w - $picture_margin_w, $picture_org_h - $picture_margin_h);
// Format thumbnail and move the files
if (($file_type == 'image/jpeg') or ($file_type == 'image/pjpeg')) {
// JPEG generator
imagejpeg ($picture_new, $file_path, $resize_quality);
} else if (($file_type == 'image/png') or ($file_type == 'image/x-png')) {
// PNG generator
imagepng ($picture_new, $file_path, $resize_quality);
} else if ($file_type == 'image/gif') {
// GIF generator
imagegif ($picture_new, $file_path, $resize_quality);
}
// Delete temporary images
imagedestroy($picture_new);
imagedestroy($picture_org);
/* Optional : Change /* to //* to (un)enable this function
// Logs EVERY thumbnail, this is useful if you want to keep track of all files.
// This function logs the entire filepath (including filename)
mysql_query("
INSERT INTO images(
image_name
) VALUES (
'$file_path
)
") or die(mysql_error());
// Adds to list of MySQL entries. Format : ID, Name
$image_array[] = array (mysql_result(mysql_query("SELECT LAST_INSERT_ID()"), 0), $file_name);//*/
}
} while ($image_set_list = next($image_set));
}
/* Optional : Change /* to //* to (un)enable this function
// Logs only ONCE, this is useful if you don't have different loose images
// In the other folders (to prevent duplicate names - auto-renaming)
mysql_query("
INSERT INTO images(
image_name
) VALUES (
'$file_name'
)
") or die(mysql_error());
// Adds to list of MySQL entries. Format : ID, Name
$image_array[] = array (mysql_result(mysql_query("SELECT LAST_INSERT_ID()"), 0), $file_name);//*/
// Completed message
echo "\n".'<br>Uw afbeelding is toegevoegd.';
return $image_array;
} else {
// Image was not a valid type!
echo "\n".'<br>Alleen JPG, PNG en GIF bestanden zijn toegestaan.';
return false;
}
}
?>
index.php:
<?
include("functie.php");
if($_SERVER['REQUEST_METHOD'] == "POST"){
$image = insertImage(foto,$_POST["naam"],$_POST["kwaliteit"], $_POST["width"], $_POST["height"]);
print($image);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="index.php" method="post" enctype="multipart/form-data">
<p>Titel:
<br>
<input name="naam" type="text" id="naam">
</p>
<p>Kwaliteit:<br>
<select name="kwaliteit">
<option value="93" selected>Kies een waarde</option>
<? for($i = 1;$i <= 100;$i++){
print("<option value=\"".$i."\">".$i."</option>");
}
?>
</select>
</p>
<p>
Breedte van het plaatje (in pixels):
<input name="width" type="text" id="width" size="4" maxlength="3">
</p>
<p>Hoogte van het plaatje (in pixels):
<input name="height" type="text" id="height" size="4" maxlength="3">
<br>
<br>
<input name="foto" type="file" id="foto">
<br>
<input name="foto" type="file" id="foto">
<br>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<p> </p>
<p>
</p>
</body>
</html>
1.048 views