Memory exhausted, upload & watermerk
Afgelopen week heb ik even een foto upload en watermerk toegevoegd aan een website.
Via een script gevonden hier op phphulp, tevens heb ik deze gecombineerd met een inlogscript.
(Hoeft niet de hoogste beveiliging te hebben, naar mijn mening is het huidige script afdoende om ongewenste upload's tegen te gaan, zeker gezien er alleen geupload kan worden naar een folder ver van de root).
Nu krijg ik de welbekende memory exhausted foutmelding. Het script heeft goed gewerkt, ik heb nog enkele zaken veranderd om hem wat op te schonen in combinatie met de website.
Na lang zoeken heb ik de handdoek maar in de ring gegooid en hoop ik dat iemand hier het probleem kan vinden waardoor het script inefficiënt geworden is?
- Reeds geprobeerd het maximum toegestane geheugen op te schroeven. (Al lijkt 20mb mij ruim voldoende voor een script als deze)
- Ik heb geprobeerd alle includes weg te halen, zodat puur het upload script draait, dit leek enigzins te helpen, maar nog niet helemaal.
- Naar mijn beste kunde heb ik het script doorzocht op problemen. (Ik ben een hobby scripter, mijn kennis zal dus achterblijven bij jullie, vandaar mijn vraag om hulp)
Quote:
'Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 10944 bytes) in /home/******/domains/******/public_html/upload.php on line 45'
Het upload script en de includes head.php en protect.php (inlogscript) zijn hieronder weergeven, in volgorde van aanroepen.
De verschillende andere includes zijn nog niet bijgevoegd, indien dit nodig is hoor ik het graag.
Beide scripts zijn ligt aangepaste versies van de standaard, bij het uploadscript moeten bijvoorbeeld de buttons nog op een andere wijze opgezet worden, hier ben ik van op de hoogte.
Ik hoor graag jullie tips en suggesties om dit te verbeteren.
protect.php
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
###############################################################
# Page Password Protect 2.13
###############################################################
# Visit http://www.zubrag.com/scripts/ for updates
###############################################################
#
# Usage:
# Set usernames / passwords below between SETTINGS START and SETTINGS END.
# Open it in browser with "help" parameter to get the code
# to add to all files being protected.
# Example: password_protect.php?help
# Include protection string which it gave you
# Add following HTML code to your page where you want to have logout link
# <a href="http://www.example.com/path/to/protected/page.php?logout=1">Logout</a>
#
###############################################################
/*
-------------------------------------------------------------------
SAMPLE if you only want to request login and password on login form.
Each row represents different user.
$LOGIN_INFORMATION = array(into every file that needs to be protected
#
'zubrag' => 'root',
'test' => 'testpass',
'admin' => 'passwd'
);
--------------------------------------------------------------------
SAMPLE if you only want to request only password on login form.
Note: only passwords are listed
$LOGIN_INFORMATION = array(
'root',
'testpass',
'passwd'
);
--------------------------------------------------------------------
*/
##################################################################
# SETTINGS START
##################################################################
// Add login/password pairs below, like described above
// NOTE: all rows except last must have comma "," at the end of line
$LOGIN_INFORMATION = array(
'******' => '******',
'******' => '******'
);
// request login? true - show login and password boxes, false - password box only
define('USE_USERNAME', true);
// User will be redirected to this page after logout
define('LOGOUT_URL', 'upload.php');
// time out after NN minutes of inactivity. Set to 0 to not timeout
// Uitloggen aangepast, gebruiker komt terug op zelfde pagina.
//define('TIMEOUT_MINUTES', 60);
// This parameter is only useful when TIMEOUT_MINUTES is not zero
// true - timeout time from last activity, false - timeout time from login
define('TIMEOUT_CHECK_ACTIVITY', true);
##################################################################
# SETTINGS END
##################################################################
///////////////////////////////////////////////////////
// do not change code below
///////////////////////////////////////////////////////
// show usage example
if(isset($_GET['help'])) {
die('Include following code into every page you would like to protect, at the very beginning (first line):<br><?php include("' . str_replace('\\','\\\\',__FILE__) . '"); ?>');
}
// timeout in seconds
$timeout = (TIMEOUT_MINUTES == 0 ? 0 : time() + TIMEOUT_MINUTES * 60);
// logout?
if(isset($_GET['logout'])) {
setcookie("verify", '', $timeout, '/'); // clear password;
header("Location: " . $_SERVER['PHP_SELF']);
// header('Location: ' . LOGOUT_URL);
exit();
}
if(!function_exists('showLoginPasswordProtect')) {
// show login form
function showLoginPasswordProtect($error_msg) {
?>
<?php include 'includes/head.php'; ?>
<title>Aanmelden</title>
</head>
<body>
<?php include 'includes/socialmedia.php'; ?>
<?php include 'includes/menu.php'; ?>
<div id="content">
<div id="left">
<div class="top" align="center"></div>
<div class="kolom" align="center">
<?php include 'includes/agenda.php'; ?>
</div>
<div class="bottom" align="center"></div>
</div>
<!-- End LEFT -->
<div id="right">
<div class="links" style="width:auto; margin-left:25px; margin-right:auto; margin-top:auto; text-align:left">
<p><h3>UPLOAD - WATERMERK</h3></p>
<p>
Dit is NIET de plaats om u op het forum aan te melden! Wilt u zichzelf aanmelden op het forum?<br /> Kies dan alstublieft in het menu voor de optie Forum, nogmaals via dit formulier meld u zich niet aan op het forum, u kunt zich via dit formulier ook niet registreren! <br />
<font color="red"><br /><?php echo $error_msg; ?></font><br /><br />
<form method="post">
<?php if (USE_USERNAME) echo 'Gebruikersnaam:<br /><input type="input" name="access_login" /><br />Wachtwoord:<br />'; ?>
<input type="password" name="access_password" /><p><input type="submit" name="Bevestig" value="Bevestig" /></p>
</p>
</form>
</div>
</p>
</div>
<!-- End RIGHT -->
</div>
<!-- End CONTENT -->
</div>
<!-- End CONTAINER -->
<?php include 'includes/scroller.php'; ?>
<?php include 'includes/footer.php'; ?>
</body>
</html>
<?php
// stop at this point
die();
}
}
// user provided password
if (isset($_POST['access_password'])) {
$login = isset($_POST['access_login']) ? $_POST['access_login'] : '';
$pass = $_POST['access_password'];
if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION)
|| (USE_USERNAME && ( !array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass ) )
) {
showLoginPasswordProtect("Wachtwoord of gebruikersnaam ongeldig.");
}
else {
// set cookie if password was validated
setcookie("verify", md5($login.'%'.$pass), $timeout, '/');
// Some programs (like Form1 Bilder) check $_POST array to see if parameters passed
// So need to clear password protector variables
unset($_POST['access_login']);
unset($_POST['access_password']);
unset($_POST['Submit']);
}
}
else {
// check if password cookie is set
if (!isset($_COOKIE['verify'])) {
showLoginPasswordProtect("");
}
// check if cookie is good
$found = false;
foreach($LOGIN_INFORMATION as $key=>$val) {
$lp = (USE_USERNAME ? $key : '') .'%'.$val;
if ($_COOKIE['verify'] == md5($lp)) {
$found = true;
// prolong timeout
if (TIMEOUT_CHECK_ACTIVITY) {
setcookie("verify", md5($lp), $timeout, '/');
}
break;
}
}
if (!$found) {
showLoginPasswordProtect("");
}
}
?>
###############################################################
# Page Password Protect 2.13
###############################################################
# Visit http://www.zubrag.com/scripts/ for updates
###############################################################
#
# Usage:
# Set usernames / passwords below between SETTINGS START and SETTINGS END.
# Open it in browser with "help" parameter to get the code
# to add to all files being protected.
# Example: password_protect.php?help
# Include protection string which it gave you
# Add following HTML code to your page where you want to have logout link
# <a href="http://www.example.com/path/to/protected/page.php?logout=1">Logout</a>
#
###############################################################
/*
-------------------------------------------------------------------
SAMPLE if you only want to request login and password on login form.
Each row represents different user.
$LOGIN_INFORMATION = array(into every file that needs to be protected
#
'zubrag' => 'root',
'test' => 'testpass',
'admin' => 'passwd'
);
--------------------------------------------------------------------
SAMPLE if you only want to request only password on login form.
Note: only passwords are listed
$LOGIN_INFORMATION = array(
'root',
'testpass',
'passwd'
);
--------------------------------------------------------------------
*/
##################################################################
# SETTINGS START
##################################################################
// Add login/password pairs below, like described above
// NOTE: all rows except last must have comma "," at the end of line
$LOGIN_INFORMATION = array(
'******' => '******',
'******' => '******'
);
// request login? true - show login and password boxes, false - password box only
define('USE_USERNAME', true);
// User will be redirected to this page after logout
define('LOGOUT_URL', 'upload.php');
// time out after NN minutes of inactivity. Set to 0 to not timeout
// Uitloggen aangepast, gebruiker komt terug op zelfde pagina.
//define('TIMEOUT_MINUTES', 60);
// This parameter is only useful when TIMEOUT_MINUTES is not zero
// true - timeout time from last activity, false - timeout time from login
define('TIMEOUT_CHECK_ACTIVITY', true);
##################################################################
# SETTINGS END
##################################################################
///////////////////////////////////////////////////////
// do not change code below
///////////////////////////////////////////////////////
// show usage example
if(isset($_GET['help'])) {
die('Include following code into every page you would like to protect, at the very beginning (first line):<br><?php include("' . str_replace('\\','\\\\',__FILE__) . '"); ?>');
}
// timeout in seconds
$timeout = (TIMEOUT_MINUTES == 0 ? 0 : time() + TIMEOUT_MINUTES * 60);
// logout?
if(isset($_GET['logout'])) {
setcookie("verify", '', $timeout, '/'); // clear password;
header("Location: " . $_SERVER['PHP_SELF']);
// header('Location: ' . LOGOUT_URL);
exit();
}
if(!function_exists('showLoginPasswordProtect')) {
// show login form
function showLoginPasswordProtect($error_msg) {
?>
<?php include 'includes/head.php'; ?>
<title>Aanmelden</title>
</head>
<body>
<?php include 'includes/socialmedia.php'; ?>
<?php include 'includes/menu.php'; ?>
<div id="content">
<div id="left">
<div class="top" align="center"></div>
<div class="kolom" align="center">
<?php include 'includes/agenda.php'; ?>
</div>
<div class="bottom" align="center"></div>
</div>
<!-- End LEFT -->
<div id="right">
<div class="links" style="width:auto; margin-left:25px; margin-right:auto; margin-top:auto; text-align:left">
<p><h3>UPLOAD - WATERMERK</h3></p>
<p>
Dit is NIET de plaats om u op het forum aan te melden! Wilt u zichzelf aanmelden op het forum?<br /> Kies dan alstublieft in het menu voor de optie Forum, nogmaals via dit formulier meld u zich niet aan op het forum, u kunt zich via dit formulier ook niet registreren! <br />
<font color="red"><br /><?php echo $error_msg; ?></font><br /><br />
<form method="post">
<?php if (USE_USERNAME) echo 'Gebruikersnaam:<br /><input type="input" name="access_login" /><br />Wachtwoord:<br />'; ?>
<input type="password" name="access_password" /><p><input type="submit" name="Bevestig" value="Bevestig" /></p>
</p>
</form>
</div>
</p>
</div>
<!-- End RIGHT -->
</div>
<!-- End CONTENT -->
</div>
<!-- End CONTAINER -->
<?php include 'includes/scroller.php'; ?>
<?php include 'includes/footer.php'; ?>
</body>
</html>
<?php
// stop at this point
die();
}
}
// user provided password
if (isset($_POST['access_password'])) {
$login = isset($_POST['access_login']) ? $_POST['access_login'] : '';
$pass = $_POST['access_password'];
if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION)
|| (USE_USERNAME && ( !array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass ) )
) {
showLoginPasswordProtect("Wachtwoord of gebruikersnaam ongeldig.");
}
else {
// set cookie if password was validated
setcookie("verify", md5($login.'%'.$pass), $timeout, '/');
// Some programs (like Form1 Bilder) check $_POST array to see if parameters passed
// So need to clear password protector variables
unset($_POST['access_login']);
unset($_POST['access_password']);
unset($_POST['Submit']);
}
}
else {
// check if password cookie is set
if (!isset($_COOKIE['verify'])) {
showLoginPasswordProtect("");
}
// check if cookie is good
$found = false;
foreach($LOGIN_INFORMATION as $key=>$val) {
$lp = (USE_USERNAME ? $key : '') .'%'.$val;
if ($_COOKIE['verify'] == md5($lp)) {
$found = true;
// prolong timeout
if (TIMEOUT_CHECK_ACTIVITY) {
setcookie("verify", md5($lp), $timeout, '/');
}
break;
}
}
if (!$found) {
showLoginPasswordProtect("");
}
}
?>
head.php
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
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
<!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=utf-8" />
<meta name="description" content="TTCT is als Opel Tigra en Opel Corsa forum ontstaan. Tuning en styling van de Corsa en Tigra is de kern van de club maar alle Opelrijders zijn welkom. Kijk rustig rond, en meld jezelf aan op ons forum" />
<meta name="keywords" content="opel, tigra, corsa, vectra, astra, tuning, styling, tunen, auto, club, autoclub, forum, autoshow, corsa tuning forum, tigra tuning forum"/>
<meta name="robots" content="index,follow"/>
<meta name="msapplication-TileColor" content="#ffc40d" />
<meta name="msapplication-TileImage" content="/mstile-144x144.png" />
<link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png" />
<link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png" />
<link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png" />
<link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png" />
<link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png" />
<link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png" />
<link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png" />
<link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png" />
<link rel="icon" type="image/png" href="/favicon-196x196.png" sizes="196x196" />
<link rel="icon" type="image/png" href="/favicon-160x160.png" sizes="160x160" />
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96" />
<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16" />
<link rel="stylesheet" href="public/css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="public/css/form.css" type="text/css" media="screen" />
<link rel="stylesheet" href="public/css/navigation.css" type="text/css" media="screen" />
<link rel="stylesheet" type="text/css" href="highslide/highslide.css" />
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" href="public/css/IE7.css" />
<![endif]-->
<script type="text/javascript" src="public/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="public/js/lib.js"></script>
<script type="text/javascript" src="highslide/highslide-with-gallery.js"></script>
<script type="text/javascript" src="public/js/easyslider1.5.js"></script>
<script type="text/javascript" src="public/js/scrollable.js"></script>
<script type="text/javascript" src="public/js/script.js"></script>
<script type="text/javascript" src="public/js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="public/js/form.js"></script>
<script type="text/javascript" src="public/js/jquery.validate.min.js"></script>
<script type="text/javascript">
hs.graphicsDir = 'highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.fadeInOut = true;
hs.numberPosition = 'caption';
hs.dimmingOpacity = 0.75;
// Add the controlbar
if (hs.addSlideshow) hs.addSlideshow({
//slideshowGroup: 'group1',
interval: 5000,
repeat: false,
useControls: true,
fixedControls: 'fit',
overlayOptions: {
opacity: .75,
position: 'bottom center',
hideOnMouseOut: true
}
});
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="TTCT is als Opel Tigra en Opel Corsa forum ontstaan. Tuning en styling van de Corsa en Tigra is de kern van de club maar alle Opelrijders zijn welkom. Kijk rustig rond, en meld jezelf aan op ons forum" />
<meta name="keywords" content="opel, tigra, corsa, vectra, astra, tuning, styling, tunen, auto, club, autoclub, forum, autoshow, corsa tuning forum, tigra tuning forum"/>
<meta name="robots" content="index,follow"/>
<meta name="msapplication-TileColor" content="#ffc40d" />
<meta name="msapplication-TileImage" content="/mstile-144x144.png" />
<link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png" />
<link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png" />
<link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png" />
<link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png" />
<link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png" />
<link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png" />
<link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png" />
<link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png" />
<link rel="icon" type="image/png" href="/favicon-196x196.png" sizes="196x196" />
<link rel="icon" type="image/png" href="/favicon-160x160.png" sizes="160x160" />
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96" />
<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16" />
<link rel="stylesheet" href="public/css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="public/css/form.css" type="text/css" media="screen" />
<link rel="stylesheet" href="public/css/navigation.css" type="text/css" media="screen" />
<link rel="stylesheet" type="text/css" href="highslide/highslide.css" />
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" href="public/css/IE7.css" />
<![endif]-->
<script type="text/javascript" src="public/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="public/js/lib.js"></script>
<script type="text/javascript" src="highslide/highslide-with-gallery.js"></script>
<script type="text/javascript" src="public/js/easyslider1.5.js"></script>
<script type="text/javascript" src="public/js/scrollable.js"></script>
<script type="text/javascript" src="public/js/script.js"></script>
<script type="text/javascript" src="public/js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="public/js/form.js"></script>
<script type="text/javascript" src="public/js/jquery.validate.min.js"></script>
<script type="text/javascript">
hs.graphicsDir = 'highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.fadeInOut = true;
hs.numberPosition = 'caption';
hs.dimmingOpacity = 0.75;
// Add the controlbar
if (hs.addSlideshow) hs.addSlideshow({
//slideshowGroup: 'group1',
interval: 5000,
repeat: false,
useControls: true,
fixedControls: 'fit',
overlayOptions: {
opacity: .75,
position: 'bottom center',
hideOnMouseOut: true
}
});
</script>
upload.php
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php include 'includes/protect.php'; ?>
<?php include 'includes/head.php'; ?>
<title>Uploaden</title>
</head>
<body>
<?php include 'includes/socialmedia.php'; ?>
<?php include 'includes/menu.php'; ?>
<div id="content">
<div id="left">
<div class="top" align="center">
</div>
<div class="kolom" align="center">
<?php include 'includes/agenda.php'; ?>
</div>
<div class="bottom" align="center">
</div>
</div>
<!-- End LEFT -->
<div id="right">
<div class="links" style="width:auto; margin-left:25px; margin-right:auto; margin-top:auto; text-align:left">
<p><h3>UPLOAD - WATERMERK </h3>
<?
//--- zet path
$path = "public/images/albums/Random/"; // met slash en chmod 777! (of lager ivm veiligheid)
//--- zet max. kb's
$maxkb = 3670016; // 40960 gedeelt door 1024 is 40 (kb) DUS 1024 keer <aantal kb's> = $maxkb
//--- watermerk path
$path_watermerk = "public/images/watermerk.png"; // dit MOET een transparante .png zijn!!!
//--- bekijk of het bestand kleiner of net zo groot als 40 kb is en of de foto wel geupload is en of extentie wel .jpg of .jpeg is!
if ($_POST['submit'] && $_FILES['userfile']['size'] <= $maxkb && !file_exists($path . $_FILES['userfile']['name']) && $_FILES['userfile']['size'] && is_uploaded_file($_FILES['userfile']['tmp_name']) && (strtolower(substr($_FILES['userfile']['name'], -3)) == "jpg" || strtolower(substr($_FILES['userfile']['name'], -4)) == "jpeg")){
//--- upload image naar $path
move_uploaded_file($_FILES['userfile']['tmp_name'], $path . $_FILES['userfile']['name']);
//--- transparante watermerk
$watermerk = imagecreatefrompng($path_watermerk);
$watermerk_width = imagesx($watermerk);
$watermerk_height = imagesy($watermerk);
imagecreatetruecolor($watermerk_width, $watermerk_height);
//--- originele image
$image = imagecreatefromjpeg($path . $_FILES['userfile']['name']);
$size = getimagesize($path . $_FILES['userfile']['name']);
//--- defineer de coordinaten van het watermerk - dit voorbeeld is links onder
-$xas = 15;
-$yas = 15;
//--- overschrijf het 'geuploade bestand' en voeg watermerk toe
imagecopymerge($image, $watermerk, $xas, $yas, 0, 0, $watermerk_width, $watermerk_height, 100);
//--- upload image
imagejpeg($image, $path . $_FILES['userfile']['name']); // max. kwaliteit
imagedestroy($image);
imagedestroy($watermerk);
echo "De foto is geupload en het watermerk is toegevoegd.<br /><br />";
echo "<button><a style=text-decoration:none;color:black href=" . $path . $_FILES['userfile']['name'] . ">Directe link</a></button>";
echo "<button><a style=text-decoration:none;color:black href=" . $_SERVER['PHP_SELF'] . ">Upload nog een foto</a></button><p>";
echo "<a href=" . $path . $_FILES['userfile']['name'] . "><img width=500 src=" . $path . $_FILES['userfile']['name'] . "></a><p>";
echo "<button><a style=text-decoration:none;color:black href=" . $_SERVER['PHP_SELF'] . "?logout=1>Uitloggen</a></button>";
}
else{
//--- errors
if ($_POST['submit'])
{
if (file_exists($path . $_FILES['userfile']['name']) && $_FILES['userfile']['name'])
echo "<p style=color:red>Error! Bestand bestaat al in de folder 'Random', hernoem de foto en probeer het opnieuw.</p>";
elseif ($_FILES['userfile']['size'] > $maxkb)
echo "<p style=color:red>Error! Bestand is groter dan " . $maxkb . "bytes(3,5Mb). Verklein de foto en probeer het opnieuw.</p>";
elseif (strtolower(substr($_FILES['userfile']['name'], -3)) != "jpg" && strtolower(substr($_FILES['userfile']['name'], -4)) != "jpeg")
echo "<p style=color:red>Error! De foto heeft een verkeerde bestandsnaam. Er mogen alleen foto's geupload worden met als bestandsnaam .jpg of .jpeg.</p>";
else
echo "<p style=color:red>Error! De foto is niet goed geupload of er is helemaal geen foto geupload. Probeer het opnieuw.</p>";
}
else
echo "<p>Selecteer een foto om te uploaden. In de foto wordt automatisch het logo verwerkt. Het bestand moet de extensie .jpg of .jpeg hebben en mag GEEN spaties bevatten. De maximale bestandsgrootte is 3,5Mb.</br></br>
Na het uploaden wordt de foto met watermerk getoond, deze is tevens te vinden onder foto's in de map 'random'</p>";
//--- formulier met enctype multipart/form-data ivm de file upload
echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" enctype=\"multipart/form-data\">";
echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $maxkb . "\" />";
echo "<input type=\"file\" style=\"margin-left:50px; margin-top:50px;\" name=\"userfile\" value=\"" . $_POST['userfile'] . "\" /><br />";
echo "<input type=\"submit\" style=\"margin-left:50px; margin-bottom:50px;\" name=\"submit\" value=\"Uploaden\" /><p>";
echo "</form>";
echo "<br /><button><a style=text-decoration:none;color:black href=" . $_SERVER['PHP_SELF'] . "?logout=1>Uitloggen</a></button>";
}
?>
</p>
</div>
</div>
<!-- End RIGHT -->
</div>
<!-- End CONTENT -->
</div>
<!-- End CONTAINER -->
<?php include 'includes/scroller.php'; ?>
<?php include 'includes/footer.php'; ?>
</body>
</html>
<?php include 'includes/head.php'; ?>
<title>Uploaden</title>
</head>
<body>
<?php include 'includes/socialmedia.php'; ?>
<?php include 'includes/menu.php'; ?>
<div id="content">
<div id="left">
<div class="top" align="center">
</div>
<div class="kolom" align="center">
<?php include 'includes/agenda.php'; ?>
</div>
<div class="bottom" align="center">
</div>
</div>
<!-- End LEFT -->
<div id="right">
<div class="links" style="width:auto; margin-left:25px; margin-right:auto; margin-top:auto; text-align:left">
<p><h3>UPLOAD - WATERMERK </h3>
<?
//--- zet path
$path = "public/images/albums/Random/"; // met slash en chmod 777! (of lager ivm veiligheid)
//--- zet max. kb's
$maxkb = 3670016; // 40960 gedeelt door 1024 is 40 (kb) DUS 1024 keer <aantal kb's> = $maxkb
//--- watermerk path
$path_watermerk = "public/images/watermerk.png"; // dit MOET een transparante .png zijn!!!
//--- bekijk of het bestand kleiner of net zo groot als 40 kb is en of de foto wel geupload is en of extentie wel .jpg of .jpeg is!
if ($_POST['submit'] && $_FILES['userfile']['size'] <= $maxkb && !file_exists($path . $_FILES['userfile']['name']) && $_FILES['userfile']['size'] && is_uploaded_file($_FILES['userfile']['tmp_name']) && (strtolower(substr($_FILES['userfile']['name'], -3)) == "jpg" || strtolower(substr($_FILES['userfile']['name'], -4)) == "jpeg")){
//--- upload image naar $path
move_uploaded_file($_FILES['userfile']['tmp_name'], $path . $_FILES['userfile']['name']);
//--- transparante watermerk
$watermerk = imagecreatefrompng($path_watermerk);
$watermerk_width = imagesx($watermerk);
$watermerk_height = imagesy($watermerk);
imagecreatetruecolor($watermerk_width, $watermerk_height);
//--- originele image
$image = imagecreatefromjpeg($path . $_FILES['userfile']['name']);
$size = getimagesize($path . $_FILES['userfile']['name']);
//--- defineer de coordinaten van het watermerk - dit voorbeeld is links onder
-$xas = 15;
-$yas = 15;
//--- overschrijf het 'geuploade bestand' en voeg watermerk toe
imagecopymerge($image, $watermerk, $xas, $yas, 0, 0, $watermerk_width, $watermerk_height, 100);
//--- upload image
imagejpeg($image, $path . $_FILES['userfile']['name']); // max. kwaliteit
imagedestroy($image);
imagedestroy($watermerk);
echo "De foto is geupload en het watermerk is toegevoegd.<br /><br />";
echo "<button><a style=text-decoration:none;color:black href=" . $path . $_FILES['userfile']['name'] . ">Directe link</a></button>";
echo "<button><a style=text-decoration:none;color:black href=" . $_SERVER['PHP_SELF'] . ">Upload nog een foto</a></button><p>";
echo "<a href=" . $path . $_FILES['userfile']['name'] . "><img width=500 src=" . $path . $_FILES['userfile']['name'] . "></a><p>";
echo "<button><a style=text-decoration:none;color:black href=" . $_SERVER['PHP_SELF'] . "?logout=1>Uitloggen</a></button>";
}
else{
//--- errors
if ($_POST['submit'])
{
if (file_exists($path . $_FILES['userfile']['name']) && $_FILES['userfile']['name'])
echo "<p style=color:red>Error! Bestand bestaat al in de folder 'Random', hernoem de foto en probeer het opnieuw.</p>";
elseif ($_FILES['userfile']['size'] > $maxkb)
echo "<p style=color:red>Error! Bestand is groter dan " . $maxkb . "bytes(3,5Mb). Verklein de foto en probeer het opnieuw.</p>";
elseif (strtolower(substr($_FILES['userfile']['name'], -3)) != "jpg" && strtolower(substr($_FILES['userfile']['name'], -4)) != "jpeg")
echo "<p style=color:red>Error! De foto heeft een verkeerde bestandsnaam. Er mogen alleen foto's geupload worden met als bestandsnaam .jpg of .jpeg.</p>";
else
echo "<p style=color:red>Error! De foto is niet goed geupload of er is helemaal geen foto geupload. Probeer het opnieuw.</p>";
}
else
echo "<p>Selecteer een foto om te uploaden. In de foto wordt automatisch het logo verwerkt. Het bestand moet de extensie .jpg of .jpeg hebben en mag GEEN spaties bevatten. De maximale bestandsgrootte is 3,5Mb.</br></br>
Na het uploaden wordt de foto met watermerk getoond, deze is tevens te vinden onder foto's in de map 'random'</p>";
//--- formulier met enctype multipart/form-data ivm de file upload
echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" enctype=\"multipart/form-data\">";
echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $maxkb . "\" />";
echo "<input type=\"file\" style=\"margin-left:50px; margin-top:50px;\" name=\"userfile\" value=\"" . $_POST['userfile'] . "\" /><br />";
echo "<input type=\"submit\" style=\"margin-left:50px; margin-bottom:50px;\" name=\"submit\" value=\"Uploaden\" /><p>";
echo "</form>";
echo "<br /><button><a style=text-decoration:none;color:black href=" . $_SERVER['PHP_SELF'] . "?logout=1>Uitloggen</a></button>";
}
?>
</p>
</div>
</div>
<!-- End RIGHT -->
</div>
<!-- End CONTENT -->
</div>
<!-- End CONTAINER -->
<?php include 'includes/scroller.php'; ?>
<?php include 'includes/footer.php'; ?>
</body>
</html>
Bijv. een foto van 67KB op schijf, ingelezen met imagecreatefrom... neemt in PHP ruim 3MB geheugen in.
Dat komt omdat GD werkt met RAW pixeldata en dat kost je per pixel 4 bytes aan geheugen.
Met andere woorden, als een foto gemaakt met een redelijke digitale camera (10 megaPixels) met GD wordt ingelezen, is dat in het geheugen 40MB.
Gewijzigd op 24/01/2014 11:27:19 door Ger van Steenderen