probleem image resize
Ik zou hier graag aan koppelen dat de afbeeldingen automatisch worden ge-resized,
maar dit lukt niet:(
ik heb het geprobeerd met imagemagicks maar tevergeefs:s
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?
ob_start();
include('conn_mysql_inc.php');
$conn = dbConnect();
$pos_query ="SELECT MAX(id) FROM artikelen";
$result2 = mysql_query($pos_query) or die(mysql_error());
while($row = mysql_fetch_array($result2)){
$plusNr=$row['MAX(id)'];
}
define ('MAX_FILE_SIZE', 512000); // we gegeven een max grootte
if (array_key_exists('upload', $_POST)) { // dit controleert of er een bestand is geupload als men op de submit knop heeft gedrukt
//(upload = name van submit button)
define('UPLOAD_DIR','/usr/local/psa/home/vhosts/stillworkingon.be/subdomains/immo/httpdocs/images/');//'/Users/reyntjensw/Desktop/php oefn/immo/images/'); ////' //zeg naar waar de file moet
$max = number_format(MAX_FILE_SIZE/1024, 1).'KB'; //omzetten naar kb
$permitted = array('image/jpeg','image/pjpeg','image/png'); // maak een array van de toegestane formaten
foreach ($_FILES['image']['name'] as $number => $file) {
$file = str_replace(' ','',$file); //verwijder de spaties
$sizeOK = false; // beginnen met een false
$typeOK = false;
if ($_FILES['image']['size'][$number] > 0 || $_FILES['image']['size'][$number] <= MAX_FILE_SIZE) {
$sizeOK = true;
}
foreach ($permitted as $type) {
if ($type == $_FILES['image']['type'][$number]) {
$typeOK = true;
break;
}
}
if ($sizeOK && $typeOK) {
switch($_FILES['image']['error'][$number]) {
case 0:
if(!file_exists(UPLOAD_DIR.$file)) {
$namen[0] = $plusNr."a.jpg";
$namen[1] = $plusNr."b.jpg";
$namen[2] = $plusNr."c.jpg";
$namen[3] = $plusNr."d.jpg";
$success = move_uploaded_file($_FILES['image']['tmp_name'][$number],UPLOAD_DIR.$namen[$number]);//verplaats en hernoem het bestand
$success = exec("/usr/local/safemode/convert -resize 150x150> -quality 60 $namen[$number] $namen[$number]");
} else {
ini_set('date.timezone', 'Europe/London');
$now = date('Y-m-d-His');
$success = move_uploaded_file($_FILES['image']['tmp_name'][$number],UPLOAD_DIR.$now.$file); //zorg er zeker voor dat je geen bestanden overschijft
}
if ($success) {
$result[] = "$file uploaded successfully";
}
else {
$result[] = "Error uploading $file. Please try again.";
}
break;
case 3:
$result[] = "Error uploading $file. Please try again.";
default:
$result[] = "System error uploading $file. Contact webmaster.";
}
}
elseif ($_FILES['image']['error'][$number] == 4) {
$result[] = 'No file selected';
}
else {
$result[] = "$file cannot be uploaded. Maximum size: $max. Acceptable file types: gif, jpg, png.";
}
}
}
?>
ob_start();
include('conn_mysql_inc.php');
$conn = dbConnect();
$pos_query ="SELECT MAX(id) FROM artikelen";
$result2 = mysql_query($pos_query) or die(mysql_error());
while($row = mysql_fetch_array($result2)){
$plusNr=$row['MAX(id)'];
}
define ('MAX_FILE_SIZE', 512000); // we gegeven een max grootte
if (array_key_exists('upload', $_POST)) { // dit controleert of er een bestand is geupload als men op de submit knop heeft gedrukt
//(upload = name van submit button)
define('UPLOAD_DIR','/usr/local/psa/home/vhosts/stillworkingon.be/subdomains/immo/httpdocs/images/');//'/Users/reyntjensw/Desktop/php oefn/immo/images/'); ////' //zeg naar waar de file moet
$max = number_format(MAX_FILE_SIZE/1024, 1).'KB'; //omzetten naar kb
$permitted = array('image/jpeg','image/pjpeg','image/png'); // maak een array van de toegestane formaten
foreach ($_FILES['image']['name'] as $number => $file) {
$file = str_replace(' ','',$file); //verwijder de spaties
$sizeOK = false; // beginnen met een false
$typeOK = false;
if ($_FILES['image']['size'][$number] > 0 || $_FILES['image']['size'][$number] <= MAX_FILE_SIZE) {
$sizeOK = true;
}
foreach ($permitted as $type) {
if ($type == $_FILES['image']['type'][$number]) {
$typeOK = true;
break;
}
}
if ($sizeOK && $typeOK) {
switch($_FILES['image']['error'][$number]) {
case 0:
if(!file_exists(UPLOAD_DIR.$file)) {
$namen[0] = $plusNr."a.jpg";
$namen[1] = $plusNr."b.jpg";
$namen[2] = $plusNr."c.jpg";
$namen[3] = $plusNr."d.jpg";
$success = move_uploaded_file($_FILES['image']['tmp_name'][$number],UPLOAD_DIR.$namen[$number]);//verplaats en hernoem het bestand
$success = exec("/usr/local/safemode/convert -resize 150x150> -quality 60 $namen[$number] $namen[$number]");
} else {
ini_set('date.timezone', 'Europe/London');
$now = date('Y-m-d-His');
$success = move_uploaded_file($_FILES['image']['tmp_name'][$number],UPLOAD_DIR.$now.$file); //zorg er zeker voor dat je geen bestanden overschijft
}
if ($success) {
$result[] = "$file uploaded successfully";
}
else {
$result[] = "Error uploading $file. Please try again.";
}
break;
case 3:
$result[] = "Error uploading $file. Please try again.";
default:
$result[] = "System error uploading $file. Contact webmaster.";
}
}
elseif ($_FILES['image']['error'][$number] == 4) {
$result[] = 'No file selected';
}
else {
$result[] = "$file cannot be uploaded. Maximum size: $max. Acceptable file types: gif, jpg, png.";
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
</head>
<body>
Code (php)
<form action="" method="post" enctype="multipart/form-data" name="multiUpload" id="multiUpload">
<p>
<label for="image1">Bestand 1:</label>
<input type="hidden" name="MAX_FILE_SIZE" value="" />
<input type="file" name="image[]" id="image1" />
</p>
<p>
<label for="image2">Bestand 2:</label>
<input type="file" name="image[]" id="image2" />
</p>
<p>
<label for="image3">Bestand 3:</label>
<input type="file" name="image[]" id="image3" />
</p>
<p>
<label for="image4">Bestand 4:</label>
<input type="file" name="image[]" id="image4" />
</p>
<p>
<input name="upload" type="submit" id="upload" value="Upload files" />
</p>
</form>
</body>
</html>
Weet iemand een oplossing? Je kan het zien rond lijn 52 en 53
Gewijzigd op 01/01/1970 01:00:00 door Wouter reyntjens