profile upload

Ask about a PHP problem here.
Post Reply
iwan010
Posts: 1
Joined: Sun Apr 17, 2016 9:08 pm

profile upload

Post by iwan010 »

hello i'm new here and i have a queston i come from netherlands so my english is bad haha

i have the next problem :

i want that my players on my maffia site can upload a profile photo

but if i want to upload i get the error its not a jpg exetions or png etc he

and my script don't update the database who can help me ?

[syntax=php] <h2>
<img src="images/icons/profiel.png" class="icon"alt="" />
<b>Persoonlijk Plaatje</b>
</h2>
<div class="info">
<form method="post" name="avatar" enctype="multipart/form-data">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="190" valign="top"><strong>Huidige Avatar:</strong></td>
<td width="396"><img src="<?php echo$data->avatar; ?>" width="100" height="100" /></td>
</tr>
<tr>
<td width="190" valign="top"><strong>Nieuwe Avatar:</strong></td>
<td width="396"><input type="file" name="bestand"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Upload" name="avatar"></td>
</tr>
</table>
</form>
<?php if(isset($_FILES['bestand']) and(!empty($_FILES['bestand']['name']))) {
//if(empty($_FILES['bestand']['name'])){
//echo "Je hebt geen plaatje/foto geselecteerd voor te gebruiken als je avatar !";
//}else{

$grootte = getimagesize( $_FILES['bestand']['tmp_name'] );
$filename = $HTTP_POST_FILES['bestand']['name'];


//als het bestand groter is dan 102400 bytes(100kb) word hij niet toegelaten
if($grootte[0] > 100 OR $grootte[1] > 100){
echo "<b>Het plaatje is te groot.<br>De grootte mag maximaal 1024 * 768 px. zijn!</b><br>";
}else{
//kijken of het bestand wel een gif, png of jpg is
if(strtoupper($extensie) == "GIF" OR strtoupper($extensie) == "JPG" OR strtoupper($extensie) == "PNG" OR strtoupper($extensie) == "BMP") {

//kijken of er een nieuwe naam aan het bestand is gegeven
// if(empty($_POST['naam'])) {
// $naam = $_FILES['bestand']['name'];
// } else {
//strip de extensie om die achter de nieuwe bestandsnaam te plakken
$x = strrchr($_FILES['bestand']['name'], ".");
$naam = "".$login."".$x."";
// }
//het bestand uploaden met de nieuwe of oude naam
move_uploaded_file($_FILES['bestand']['tmp_name'], "avatermap/" . $users);
mysql_query("Update `users` Set `avatar`='avatermap/".$users."' Where login='".$login."'");
echo "<b>Het plaatje is succesvol geupload en is nu uw avatar.</b><br>";
} else {
echo "<b>De extentie van het plaatje moet eindigen met .gif, .png, .jpg, .jpeg of .bmp !</b><br>";
}
}
}
?>
<br style="clear: both" />
</div>[/syntax]
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: profile upload

Post by jacek »

Hey,

It looks like the $extensie variable is not being defined - I can only see that used in the id statement anyway. This is also likely why you're always getting the extension error instead of the upload code being run.

You probably want something like this to get the file extensions

[syntax=php]$extensie = end(explode('.', $file_name));[/syntax]
which will give you the extension.
Image
Post Reply