HTML interesse |
|
Ik heb nu een probleem in mijn script. Als iemand nu een avater upload dan geeft die een foutmelding als de afmetingen van het plaatje te groot zijn. Nu is de bedoeling dat dit script en het script daaronder samengevoegd worden. Het lukte mij zelf eigenlijk niet dus daarom post ik het hier nog even:
<?
if ($_FILES['upload']['type'] !== 'image/pjpeg'){
echo"<br><br><center>Onbekend bestandstype. Alleen JPG-bestanden worden geaccepteerd!<br><br><a href=upload_form.html>Ga terug en probeer opnieuw</a></b></center>";
exit;
}
if (!empty($_FILES['upload']['name'])) {
function NumGen( $length ) {
$vandaag = getdate();
$randnum = $vandaag['yday'];
for ( $i = 0; $i < $length; $i++ )
$randnum .= rand( 0, 9 );
return $randnum;
}
$cod= NumGen(5);
$cod1= "_";
$code= $cod.$cod1;
$up_file=$_FILES['upload']['tmp_name'];
$srcimage = imagecreatefromjpeg($up_file);
$width = imageSX($srcimage);
$height = imageSY($srcimage);
if($width <= 800 && $height <= 600){
$t_width=$width;
} else {
if ($height < $width){
$t_width = 800;
}
else {
$t_width = 600;
}
}
$newh1= $height / $width;
$newh2= $newh1 * $t_width;
$destimage = imagecreatetruecolor($t_width,$newh2);
imagecopyresampled($destimage,$srcimage,0,0,0,0,$t_width,$newh2,$width,$height);
ob_start();
ImageJPEG($destimage,'',100);
$buffer = ob_get_contents();
ob_end_clean();
$filename='files/'.$code.'pic.jpg';
$handle = fopen($filename, 'ab');
fwrite($handle, $buffer);
fclose($handle);
} else {
die("Geen filenaam geselecteerd.");
}
?>
En het script wat ik tot nu toe al had:
<?php
include ("config.php");
include ("functions.php");
CheckLogin();
if(isset($_POST['avatar']))
$upload_dir = $_SERVER['DOCUMENT_ROOT'] . "avatar/";
$avatar = $_FILES['upload']['name'];
$extensie = $_FILES['upload']['type'];
$size = $_FILES['upload']['size'];
$ex_avatar = $_POST['ex_avatar'];
if ($_FILES['upload']['type'] == "image/jpeg" || $_FILES['upload']['type'] == "image/pjpeg" || $_FILES['upload']['type'] == "image/gif" || $_FILES['upload']['type'] == "image/pjpeg" || $_FILES['upload']['type'] == "image/x-png")
{
if($size > 108000)
{
exit("Uw foto mag niet groter zijn dan 8 Kb");
}
if (!move_uploaded_file($_FILES['upload']['tmp_name'], $upload_dir . $_FILES['upload']['name']))
{
exit (" avatar niet upgeload");
}
$insert = mysql_query ("UPDATE `WNP_nickname` SET `avatar` = '$avatar', `ex_avatar` = '$ex_avatar' WHERE `nickname` = '".$_SESSION['nickname']."'") or die (mysql_error());
echo "Avatar toegevoegd";
}
else
{
echo "Verkeerde extensie";
}
}
if(!isset($_POST['avatar']))
{
?>
<? if ($_FILES['upload']['type'] !== 'image/pjpeg'){ echo"<br><br><center>Onbekend bestandstype. Alleen JPG-bestanden worden geaccepteerd!<br><br><a href=upload_form.html>Ga terug en probeer opnieuw</a></b></center>"; } if (!empty($_FILES['upload']['name'])) { function NumGen( $length ) { $randnum = $vandaag['yday']; for ( $i = 0; $i < $length; $i++ ) $randnum .= rand( 0, 9 ); return $randnum; } $cod= NumGen(5); $cod1= "_"; $code= $cod.$cod1; $up_file=$_FILES['upload']['tmp_name']; $srcimage = imagecreatefromjpeg($up_file); $width = imageSX($srcimage); $height = imageSY($srcimage); if($width <= 800 && $height <= 600){ $t_width=$width; } else { if ($height < $width){ $t_width = 800; } else { $t_width = 600; } } $newh1= $height / $width; $newh2= $newh1 * $t_width; $destimage = imagecreatetruecolor($t_width,$newh2); imagecopyresampled($destimage,$srcimage,0,0,0,0,$t_width,$newh2,$width,$height); ImageJPEG($destimage,'',100); $filename='files/'.$code.'pic.jpg'; $handle = fopen($filename, 'ab'); } else { die("Geen filenaam geselecteerd."); } ?> En het script wat ik tot nu toe al had: <?php include ("config.php"); include ("functions.php"); CheckLogin(); if(isset($_POST['avatar'])) $upload_dir = $_SERVER['DOCUMENT_ROOT'] . "avatar/"; $avatar = $_FILES['upload']['name']; $extensie = $_FILES['upload']['type']; $size = $_FILES['upload']['size']; $ex_avatar = $_POST['ex_avatar']; if ($_FILES['upload']['type'] == "image/jpeg" || $_FILES['upload']['type'] == "image/pjpeg" || $_FILES['upload']['type'] == "image/gif" || $_FILES['upload']['type'] == "image/pjpeg" || $_FILES['upload']['type'] == "image/x-png") { if($size > 108000) { exit("Uw foto mag niet groter zijn dan 8 Kb"); } if (!move_uploaded_file($_FILES['upload']['tmp_name'], $upload_dir . $_FILES['upload']['name'])) { exit (" avatar niet upgeload"); } $insert = mysql_query ("UPDATE `WNP_nickname` SET `avatar` = '$avatar', `ex_avatar` = '$ex_avatar' WHERE `nickname` = '".$_SESSION['nickname']."'") or die (mysql_error()); echo "Avatar toegevoegd"; } else { echo "Verkeerde extensie"; } } if(!isset($_POST['avatar'])) { ?>
|