Add photo to newssystem

Hallo,

Ik ben nog niet zolang bezig met php, dus kraak me niet te snel af :). Ik ben bezig met het maken van een website. Deze website moet een nieuwssysteem beschikken, waar ook foto’s bij toegevoegd kunnen worden. Ik ben al redelijk ver, maar het deel om foto’s toe te voegen lukt me nog niet. Ziet iemand waar ik ergens fout zit?

Alvast Bedankt!

Hi,

I’m working on a newssystem for a website that I’m making. I just started with php so please be patient! :slight_smile: I already can add, update and delete news, but the part to add photo’s to a newsmessage still don’t work.

Already thanks!

Here is the code:

[php]<?php
ini_set(‘display_errors’, 1); // 0 = uit, 1 = aan
error_reporting(E_ALL);

if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {
ini_set(‘display_errors’, 1); // 0 = uit, 1 = aan
error_reporting(E_ALL);

if ($_POST['voegtoe'])
ini_set('display_errors', 1); // 0 = uit, 1 = aan
error_reporting(E_ALL);
{	
	$photoFileName = $_FILES['photo']['name']; // get client side file name
	if ($photoFileName) // file uploaded
	{
		$fileNameParts = explode(".", $photoFileName);
		$fileExtension = end($fileNameParts); // part behind last dot

		if ($fileExtension != "jpg" && $fileExtension != "JPEG"	&& $fileExtension != "JPG")
		{
			die ("Kies aub een <b>jpg</b> foto, ga terug en probeer het opnieuw.");
		}
		
		$photoSize = $_FILES['photo']['size']; // size of uploaded file
		if ($photoSize == 0)
		{
			die ("Kies eerst een foto en klik daarna pas op \"voegtoe\", ga terug en probeer het opnieuw.");
		}
	
		// read photo
		$tempFileName = $_FILES['photo']['tmp_name']; // temporary file at server side
		$src_img = imagecreatefromjpeg ($tempFileName);

		$width = imagesx($src_img); // get original source image width
		$height = imagesy($src_img); // and height
		
		// create small thumbnail
		if (($height * 3) / 4 >  $width)
		{
			$dest_height = 260;
			$dest_width = (260 * $width) / $height;
		}
		else
		{
			$dest_width = 200;
			$dest_height = (200 * $height) / $width;
		}
		
		$dest_img = imagecreatetruecolor($dest_width, $dest_height);

		$result = imagecopyresampled($dest_img, $src_img,0, 0, 0, 0,	$dest_width, $dest_height,$width, $height); // resize the image

		$indexke = strrpos($photoFileName, '.');
		$photoFileName = substr ($photoFileName, 0, $indexke) . ".png";
		
		imagepng($dest_img, "fotos_groot/thumbs/" . $photoFileName); // save image
		imagepng($src_img, "fotos_groot/fotos/" . $photoFileName);
		
		imagedestroy($src_img);
		imagedestroy($dest_img);

		mysql_query("INSERT INTO nieuws_fotos_groot (naam, height, width, height_groot, width_groot) 
						values ('$photoFileName', '$dest_height', '$dest_width', '$height', '$width')") or die ("fout bij het vastleggen van de foto in de databank");
	}
}

}

if (isset($id)) {
$result = mysql_query(“SELECT *
FROM nieuws_fotos_groot
WHERE id = ‘$id’”);
$show_msg = mysql_fetch_array($result);

echo (	"<script language=\"javascript\" type=\"text/javascript\">\n<!--\n" .
	"opener.document.submitform.boodschap.value += \" [foto $show_msg[naam] width=$show_msg[width] height=$show_msg[height]]" . $id . "[/foto]\";\n" .
	"window.close();\n" .
	"// -->\n</script>\n");   

// else show the form to submit new data:
}
else
{
?>
[/php]

[code]

\n");
if ($teller++ % 2 == 0)
echo ("\n");
}
?>[/php]
[code]

Selecteer een foto
[/code] [php]<?php $teller = 1;

$results = mysql_query(“SELECT *
FROM nieuws_fotos_groot
WHERE id != ‘0’”);
while($show_msg = mysql_fetch_array($results))
{
echo("<td align=“center”><table border=“0” cellspacing=“2” cellpadding=“0” bgcolor="#c0c0c0">

<a href=“foto_groot.php?id=$show_msg[id]&naam=$show_msg[naam]”><img src=“fotos_groot/thumbs/$show_msg[naam]” width="$show_msg[width]" height="$show_msg[height]" border=“0” alt=“klik om te selecteren”>


		<form onsubmit="hidebuttons(this)" method="post" action="<?php $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
		<table border="0" bgcolor="#cccccc" cellspacing="1" cellpadding="0" width="95%">
			<tr>
				<td>
					<table border="0" cellspacing="5" width="100%" bgcolor="#f6f6f6">
						<tr>
							<td>
								<table border="0" cellspacing="5" width="100%">
									<tr>
										<td class="tekst" valign="top" colspan="3"><font size="-2">foto toevoegen<br><br></font>
										</td>
									</tr>
									<tr>
										<td class="tekst" valign="top"><b>Selecteer foto</b>
										</td>
										<td><input type="file" name="photo" class="formke" size="25" accept="image/jpeg"><br><br>
										</td>
										<td class="tekst" valign="top">
											<input type="submit" value=" Voeg toe " class="form" name="voegtoe"><input type="button" value=" wacht even " class="form" name="voegtoe_hidden" disabled style="display:none">
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</div>
	</form>
	<input type="Button" value=" Cancel " class="form" OnClick="self.close();">
	</td>
</tr>
[/code] [php]<?php } mysql_close($connection); ?>[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service