Formulier afhandeling
Warning: fopen(): open_basedir restriction in effect. File(/tmp/phpjgbjG9) is not within the allowed path(s): (.) in /mnt/storage1/k/kl/kleefbaarnederland.nl/html/extenda/testform.php on line 83
De oorspronkelijke code zou een mail moeten versturen met daaraan een attachment verbonden. Handig om bijvoorbeeld iemand een bestand mee te laten sturen.
In feite heb ik nu 2 vragen.
1. Wat moet ik doen om die ... is not within the allowed path(s): (.) ... foutmeldingen eruit te krijgen.
2. Heeft iemand misschien een beter script waarbij ik data direct in de MySql weg kan schrijven, het bestand upload in een directory en zelf een mooi mailtje krijg dat er weer iemand wat heeft geupload?
hier voor de volledigheid nog even de basiscode waarover ik die foutmelding krijg:
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
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
<?php
$maxfilesize = 100000; // in bytes
$mailto = '[email protected]';
define ('CR', "\n");
define ('CRLF', "\r\n");
// Initialize
$msg = '';
$name= '';
$email = '';
$remark = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['name'])) $name = $_POST['name'];
if (isset($_POST['email'])) $email = $_POST['email'];
if (isset($_POST['remark'])) $remark = $_POST['remark'];
if (get_magic_quotes_gpc()) {
$name = stripslashes($name);
$email = stripslashes($email);
$remark = stripslashes($remark);
}
// Check for errors
if (!preg_match('/\S+/', $name)) $msg .= '<b>No name specified</b><br />';
if (!preg_match('/\S+/', $email)) $msg .= '<b>No email address specified</b><br />';
elseif (!preg_match('/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4}$/', $email)) $msg .= '<b>Invalid email address</b><br />';
if (!$_FILES['file1']['tmp_name']) {
$msg .= '<b>No file was uploaded</b><br />';
} else {
if (is_uploaded_file($_FILES['file1']['tmp_name'])) {
// check for any errors
switch ($_FILES['file1']['error']) {
case 0:
break;
case 1:
$msg .= '<b>Filesize exceeds maximum specified for upload_max_filesize</b><br />';
break;
case 2:
$msg .= '<b>Filesize exceeds MAX_FILE_SIZE specified in the form</b><br />';
break;
case 3:
$msg .= '<b>File was only partially received</b><br />';
break;
case 4:
$msg .= '<b>No file was uploaded</b><br />';
break;
case 5:
$msg .= '<b>Uploaded file is empty</b><br />';
break;
}
} else {
$msg = '<b>Possible file upload attack</b><br />';
}
}
if (!preg_match('/\S+/', $remark)) $msg .= '<b>No remark specified</b><br />';
// no errors?
if (!$msg) {
// create mail and attach the uploaded file
$fp = fopen($_FILES['file1']['tmp_name'], 'r');
$attachment = fread($fp, $_FILES['file1']['size']);
$attachment = chunk_split(base64_encode($attachment));
$mailheader = 'From: "'.$name.'"<'.$email.'>'.CRLF.
'MIME-Version: 1.0'.CRLF.
'Content-Type: multipart/mixed; boundary="MIME_BOUNDARY"'.CRLF.
'X-Sender: <'.$email.'>'.CRLF.
'X-Mailer: PHP4'.CRLF.
'X-Priority: 3'.CRLF.
'Return-Path: <'.$email.'>'.CRLF;
$subject = 'Uploaded file from '.$name;
$mailcontent = '--MIME_BOUNDARY'.CR.
'Content-Type: text/plain; charset="iso-8859-1"'.CR.
'Content-Transfer-Encoding: quoted-printable'.CR.
CR.$remark.CR.
CR.'--MIME_BOUNDARY'.CR.
'Content-Type: '.$_FILES['file1']['type'].'; name="'.$_FILES['file1']['name'].'"'.CR.
'Content-disposition: attachment'.CR.
'Content-Transfer-Encoding: base64'.CR.
CR.$attachment.CR.
'--MIME_BOUNDARY--'.CR;
mail($mailto, $subject, $mailcontent, $mailheader);
$msg = '<b>Your file has been sent successfully!</b><br />';
$name = '';
$email = '';
$remark = '';
}
}
?>
$maxfilesize = 100000; // in bytes
$mailto = '[email protected]';
define ('CR', "\n");
define ('CRLF', "\r\n");
// Initialize
$msg = '';
$name= '';
$email = '';
$remark = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['name'])) $name = $_POST['name'];
if (isset($_POST['email'])) $email = $_POST['email'];
if (isset($_POST['remark'])) $remark = $_POST['remark'];
if (get_magic_quotes_gpc()) {
$name = stripslashes($name);
$email = stripslashes($email);
$remark = stripslashes($remark);
}
// Check for errors
if (!preg_match('/\S+/', $name)) $msg .= '<b>No name specified</b><br />';
if (!preg_match('/\S+/', $email)) $msg .= '<b>No email address specified</b><br />';
elseif (!preg_match('/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4}$/', $email)) $msg .= '<b>Invalid email address</b><br />';
if (!$_FILES['file1']['tmp_name']) {
$msg .= '<b>No file was uploaded</b><br />';
} else {
if (is_uploaded_file($_FILES['file1']['tmp_name'])) {
// check for any errors
switch ($_FILES['file1']['error']) {
case 0:
break;
case 1:
$msg .= '<b>Filesize exceeds maximum specified for upload_max_filesize</b><br />';
break;
case 2:
$msg .= '<b>Filesize exceeds MAX_FILE_SIZE specified in the form</b><br />';
break;
case 3:
$msg .= '<b>File was only partially received</b><br />';
break;
case 4:
$msg .= '<b>No file was uploaded</b><br />';
break;
case 5:
$msg .= '<b>Uploaded file is empty</b><br />';
break;
}
} else {
$msg = '<b>Possible file upload attack</b><br />';
}
}
if (!preg_match('/\S+/', $remark)) $msg .= '<b>No remark specified</b><br />';
// no errors?
if (!$msg) {
// create mail and attach the uploaded file
$fp = fopen($_FILES['file1']['tmp_name'], 'r');
$attachment = fread($fp, $_FILES['file1']['size']);
$attachment = chunk_split(base64_encode($attachment));
$mailheader = 'From: "'.$name.'"<'.$email.'>'.CRLF.
'MIME-Version: 1.0'.CRLF.
'Content-Type: multipart/mixed; boundary="MIME_BOUNDARY"'.CRLF.
'X-Sender: <'.$email.'>'.CRLF.
'X-Mailer: PHP4'.CRLF.
'X-Priority: 3'.CRLF.
'Return-Path: <'.$email.'>'.CRLF;
$subject = 'Uploaded file from '.$name;
$mailcontent = '--MIME_BOUNDARY'.CR.
'Content-Type: text/plain; charset="iso-8859-1"'.CR.
'Content-Transfer-Encoding: quoted-printable'.CR.
CR.$remark.CR.
CR.'--MIME_BOUNDARY'.CR.
'Content-Type: '.$_FILES['file1']['type'].'; name="'.$_FILES['file1']['name'].'"'.CR.
'Content-disposition: attachment'.CR.
'Content-Transfer-Encoding: base64'.CR.
CR.$attachment.CR.
'--MIME_BOUNDARY--'.CR;
mail($mailto, $subject, $mailcontent, $mailheader);
$msg = '<b>Your file has been sent successfully!</b><br />';
$name = '';
$email = '';
$remark = '';
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Mail with attachment</title>
</head>
<body>
<form enctype="multipart/form-data" method="post" action="">
From: <input type="text" name="name" maxlength="30" value="" /><br />
Email: <input type="text" name="email" maxlength="50" value="" /><br />
File: <input type="hidden" name="MAX_FILE_SIZE" value="" /><input type="file" name="file1" /><br />
Remark:<br /><textarea name="remark" rows="9" cols="45" > </textarea><br />
<input type="submit" value="submit" />
</form>
</body>
</html>
Dank alvast voor eventuele hulp!
bij windows zorg je dat je op c:\> een map genaamt tmp hebt staan die je chmod met 777.. Doe dit voor de zekerheid ook ff in je www diretje.. weet niet meer zeker welke gebruikt wordt..
Bij apache moet je in je www diretje een map aanmaken genaamd tmp met chmod 777.. :)
als dit allemaal niet voor je werkt, moet je ff in je php.ini kijken naar de tmp (temp) directory.. kijken waar dat op geset is als dit te vinden is :) denk dat je wel ff zoet bent :x succes!
Jahaa ik heb mijn site gehost bij LADOT.... dus die moeten mij dan vertellen waar de temp directorie zit? Ik ga het proberen, dank voor je hulp.
Warning: fopen(): open_basedir restriction in effect. File(/tmp/phpjgbjG9) is not within the allowed path(s): (.) in /mnt/storage1/k/kl/kleefbaarnederland.nl/html/extenda/testform.php on line 83
de temp dir is /tmp; lees de foutmelding. De foutmelding is ook dat je daar niet mag schrijven.
upload_tmp_dir string
The temporary directory used for storing files when doing file upload. Must be writable by whatever user PHP is running as. If not specified PHP will use the system's default.
Kortom: ini_set("upload_tmp_dir","/pad/naar/tmp/in/je/home/dir");
Kun je de rechten niet veranderen via een chmod?
CHMOD is ook niet het probleem! Het probleem is dat /tmp buiten je home directory ligt, en je van php niets buiten je home directory (open_basedir directive) mag uitvoeren. Vandaar.
Zij hebben wel standaard de savemode aanstaan, kan dat ook problemen geven? (kan ook niet uitgezet overigens --> policy)