avatar upload hulp
ik heb een script dat niet compleet werkt.
wat mijn probleem is dat ik de afbeelding wel in mijn database krijg maar niet in mijn files van de server.
kan iemand mij vertellen of helpen met wat ik fout doe...
dit is mijn settings pagina waar gebruikers straks de afbeelding kunnen uploaden.
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
include 'core/init.php';
protect_page();
include 'includes/overall/header.php';
if (empty($_POST) === false) {
$required_fields = array('firstname', 'email');
foreach($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'velden met een ster zijn verplicht in te vullen.';
break 1;
}
}
if (empty($errors) === true) {
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'Een geldig email is verplicht.';
} else if (email_exists($_POST['email']) === true && $user_data['email'] !== $_POST['email']) {
}
}
}
?>
include 'core/init.php';
protect_page();
include 'includes/overall/header.php';
if (empty($_POST) === false) {
$required_fields = array('firstname', 'email');
foreach($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'velden met een ster zijn verplicht in te vullen.';
break 1;
}
}
if (empty($errors) === true) {
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'Een geldig email is verplicht.';
} else if (email_exists($_POST['email']) === true && $user_data['email'] !== $_POST['email']) {
}
}
}
?>
<h1>Profiel settings</h1>
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
if (isset($_GET['succes']) === true && empty($_GET['succes']) === true) {
echo 'Jou profiel pagina is verandert';
} else {
if (empty($_POST) === false && empty($errors) === true) {
$update_data = array(
'firstname' => $_POST['firstname'],
'lastname' => $_POST['lastname'],
'email' => $_POST['email'],
'over_jezelf' => $_POST['over_jezelf'],
'allow_email' => ($_POST['allow_email'] == 'on') ? 1 : 0
);
update_user($session_user_id, $update_data);
header('Location: settings.php?succes');
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
if (isset($_GET['succes']) === true && empty($_GET['succes']) === true) {
echo 'Jou profiel pagina is verandert';
} else {
if (empty($_POST) === false && empty($errors) === true) {
$update_data = array(
'firstname' => $_POST['firstname'],
'lastname' => $_POST['lastname'],
'email' => $_POST['email'],
'over_jezelf' => $_POST['over_jezelf'],
'allow_email' => ($_POST['allow_email'] == 'on') ? 1 : 0
);
update_user($session_user_id, $update_data);
header('Location: settings.php?succes');
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
<form action="" method="post">
<ul>
<li>
firstname*:<br>
<input type="text" name="firstname" value="">
</li>
<li>
lastname:<br>
<input type="text" name="lastname" value="">
</li>
<li>
email*:<br>
<input type="text" name="email" value="">
</li>
<li>
over jezelf:<br>
<textarea name="over_jezelf" rows="6" cols="30" maxlength="500" value=""></textarea>
</li>
<li>
<input type="checkbox" name="allow_email"> Wilt u onze nieuws brieven ontvangen?
</li>
<li>
<input type="submit" value="update">
</li>
</ul>
</form>
hier volgen dan de upload.php
en de view.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
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
<?php
if (isset($_POST['submit']))
{
$name = $_FILES['myfile']['name'];
$tmp_name = $_FILES['myfile']['tmp_name'];
if ($name)
{
$location = "avator/$name";
move_uploaded_file($tmp_name,$location);
$query = mysql_query("UPDATE users SET imagelocation='$location' WHERE username='$username'");
die("jou foto is uploaded");
}
else
die("please select a file");
}
echo "upload your image:
<form action='settings.php' method='post' enctype='multipart/form-data'>
file: <input type='file' name='myfile'> <input type='submit' name='submit' value='uploaden'>
</form>";
?>
if (isset($_POST['submit']))
{
$name = $_FILES['myfile']['name'];
$tmp_name = $_FILES['myfile']['tmp_name'];
if ($name)
{
$location = "avator/$name";
move_uploaded_file($tmp_name,$location);
$query = mysql_query("UPDATE users SET imagelocation='$location' WHERE username='$username'");
die("jou foto is uploaded");
}
else
die("please select a file");
}
echo "upload your image:
<form action='settings.php' method='post' enctype='multipart/form-data'>
file: <input type='file' name='myfile'> <input type='submit' name='submit' value='uploaden'>
</form>";
?>
hier volgt de viw.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
if (mysql_num_rows($query)==0)
die("user not found");
else
{
$row = mysql_fetch_assoc($query);
$location = $row['imagelocation'];
echo "<img src='$location' width='100' height='100'>";
}
?>
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
if (mysql_num_rows($query)==0)
die("user not found");
else
{
$row = mysql_fetch_assoc($query);
$location = $row['imagelocation'];
echo "<img src='$location' width='100' height='100'>";
}
?>
Code (php)
1
2
3
4
5
6
2
3
4
5
6
$location = "avator/$name";
move_uploaded_file($tmp_name,$location);
$query = mysql_query("UPDATE users SET imagelocation='$location' WHERE username='$username'");
die("jou foto is uploaded");
move_uploaded_file($tmp_name,$location);
$query = mysql_query("UPDATE users SET imagelocation='$location' WHERE username='$username'");
die("jou foto is uploaded");
Op deze manier sta je gewoonweg zelf maar te beslissen of het gelukt is, of juist niet. Het gebruik van die() is overigens ook uit den boze. Een script hoort niet te sterven.
ik heb nu alle php bestanden samen gevoegd op mijn settings pagina en de die() functies verwijdert en naar echo geplaatst.
nu plaatst hij wel mijn afbeelding in de database van de gebruiker maar hij stopt ze niet in mijn map files op de server die ik genoemd heb (avators)...
ik heb mijn error reporing aan staan maar die weergeeft niks.
mvg en bedankt voor de reactie
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
include 'core/init.php';
protect_page();
include 'includes/overall/header.php';
if (empty($_POST) === false) {
$required_fields = array('firstname', 'email');
foreach($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'velden met een ster zijn verplicht in te vullen.';
break 1;
}
}
if (empty($errors) === true) {
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'Een geldig email is verplicht.';
} else if (email_exists($_POST['email']) === true && $user_data['email'] !== $_POST['email']) {
}
}
}
?>
include 'core/init.php';
protect_page();
include 'includes/overall/header.php';
if (empty($_POST) === false) {
$required_fields = array('firstname', 'email');
foreach($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'velden met een ster zijn verplicht in te vullen.';
break 1;
}
}
if (empty($errors) === true) {
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'Een geldig email is verplicht.';
} else if (email_exists($_POST['email']) === true && $user_data['email'] !== $_POST['email']) {
}
}
}
?>
<h1>Profiel settings</h1>
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
if (isset($_GET['succes']) === true && empty($_GET['succes']) === true) {
echo 'Jou profiel pagina is verandert';
} else {
if (empty($_POST) === false && empty($errors) === true) {
$update_data = array(
'firstname' => $_POST['firstname'],
'lastname' => $_POST['lastname'],
'email' => $_POST['email'],
'over_jezelf' => $_POST['over_jezelf'],
'allow_email' => ($_POST['allow_email'] == 'on') ? 1 : 0
);
update_user($session_user_id, $update_data);
header('Location: settings.php?succes');
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
if (isset($_GET['succes']) === true && empty($_GET['succes']) === true) {
echo 'Jou profiel pagina is verandert';
} else {
if (empty($_POST) === false && empty($errors) === true) {
$update_data = array(
'firstname' => $_POST['firstname'],
'lastname' => $_POST['lastname'],
'email' => $_POST['email'],
'over_jezelf' => $_POST['over_jezelf'],
'allow_email' => ($_POST['allow_email'] == 'on') ? 1 : 0
);
update_user($session_user_id, $update_data);
header('Location: settings.php?succes');
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
<form action="" method="post">
<ul>
<li>
firstname*:<br>
<input type="text" name="firstname" value="">
</li>
<li>
lastname:<br>
<input type="text" name="lastname" value="">
</li>
<li>
email*:<br>
<input type="text" name="email" value="">
</li>
<li>
over jezelf:<br>
<textarea name="over_jezelf" rows="6" cols="30" maxlength="500" value=""></textarea>
</li>
<li>
<input type="checkbox" name="allow_email"> Wilt u onze nieuws brieven ontvangen?
</li>
<li>
<input type="submit" value="update">
</li>
</ul>
</form>
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
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
<?php
$username = $_SESSION['user_id'];
if (isset($_POST['submit']))
{
$name = $_FILES['myfile']['name'];
$tmp_name = $_FILES['myfile']['tmp_name'];
if ($name)
{
$location = "avator/$name";
move_uploaded_file($tmp_name,$location);
$query = mysql_query("UPDATE users SET imagelocation='$location' WHERE user_id='$username'");
echo "jou foto is uploaded <a href='view.php'>home</a>";
}
else
echo "please select a file";
}
echo "upload your image:
<form action='settings.php' method='post' enctype='multipart/form-data'>
file: <input type='file' name='myfile'> <input type='submit' name='submit' value='uploaden'>
</form>";
?>
$username = $_SESSION['user_id'];
if (isset($_POST['submit']))
{
$name = $_FILES['myfile']['name'];
$tmp_name = $_FILES['myfile']['tmp_name'];
if ($name)
{
$location = "avator/$name";
move_uploaded_file($tmp_name,$location);
$query = mysql_query("UPDATE users SET imagelocation='$location' WHERE user_id='$username'");
echo "jou foto is uploaded <a href='view.php'>home</a>";
}
else
echo "please select a file";
}
echo "upload your image:
<form action='settings.php' method='post' enctype='multipart/form-data'>
file: <input type='file' name='myfile'> <input type='submit' name='submit' value='uploaden'>
</form>";
?>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
$username = $_SESSION['user_id'];
$query = mysql_query("SELECT imagelocation FROM users WHERE user_id='$username'");
if (mysql_num_rows($query)==0)
echo "user not found";
else
{
$row = mysql_fetch_assoc($query);
$location = $row['imagelocation'];
echo "<img src='$location' width='100' height='100'>";
}
?>
$username = $_SESSION['user_id'];
$query = mysql_query("SELECT imagelocation FROM users WHERE user_id='$username'");
if (mysql_num_rows($query)==0)
echo "user not found";
else
{
$row = mysql_fetch_assoc($query);
$location = $row['imagelocation'];
echo "<img src='$location' width='100' height='100'>";
}
?>
Code (php)
1
2
3
4
5
6
2
3
4
5
6
move_uploaded_file($tmp_name,$location);
$query = mysql_query("UPDATE users SET imagelocation='$location' WHERE user_id='$username'");
echo "jou foto is uploaded <a href='view.php'>home</a>";
$query = mysql_query("UPDATE users SET imagelocation='$location' WHERE user_id='$username'");
echo "jou foto is uploaded <a href='view.php'>home</a>";
Ga eerst een kijken of move_uploaded_file gelukt is, en dan mysql_query.
Nu ga je er zelf maar vanauit dat het gelukt is, wat niet juist is.
tutorial wel wat voor jou is. :-)
Ik denk dat deze