Member Avatar for Puster

Hello!
I have made at site for my company that are going to upload images, and when the image is uploaded a watermark with copyright are being set in the bottom. But I got errors.

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: Filename cannot be empty in C:\xampp\htdocs\sjohaugbygg\admin\upload.php on line 66

Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in C:\xampp\htdocs\sjohaugbygg\admin\upload.php on line 68

Warning: imagecopymerge() expects parameter 1 to be resource, null given in C:\xampp\htdocs\sjohaugbygg\admin\upload.php on line 73

Warning: imagejpeg() expects parameter 1 to be resource, null given in C:\xampp\htdocs\sjohaugbygg\admin\upload.php on line 75

Warning: imagedestroy() expects parameter 1 to be resource, null given in C:\xampp\htdocs\sjohaugbygg\admin\upload.php on line 77
Column count doesn't match value count at row 1

What is wrong?
Posting the php codes her.

Upload.php

<?php
//kontakter database, får utf koding etc.
include 'connect.php';
?>
<script type="text/javascript">
window.onload=function() {
function countdown() {
if ( typeof countdown.counter == 'undefined' ) {
    countdown.counter = 4;
    }
if(countdown.counter > 0) {
        document.getElementById('count').innerHTML = countdown.counter--;
    setTimeout(countdown, 1000);
    }
else {
    location.href = '';
    }
}
countdown();
};
</script>
<style type="text/css">
.footer{
	height: 30;
	width: auto;
	background-image:url(images/footer.png);
	font-family: Arial, Helvetica, sans-serif;
	color: #FFF;
	line-height: 2em;}
.header{
	height: 100;
	width: auto;
	background-image:url(images/header.png);
	font-family: Arial, Helvetica, sans-serif;
	color: #FFF;
	line-height: 2em;}
.siden{
	height: 800px;
	width: 825px;
	margin-left: auto;
	margin-right: auto;
	font-family: Arial, Helvetica, sans-serif;
	height: auto;
	padding-bottom: 20px;}
</style>
<div class="header"><div class="siden"><img src="images/header_admin.png" align="left"></div></div>
<div class="siden">
<?php
//ting om filen som blir lastet opp
$name = $_FILES["myfile"]["name"];
$size = $_FILES["myfile"]["size"];
$temp = $_FILES["myfile"]["tmp_name"];
$error = $_FILES["myfile"]["error"];
$title = htmlentities(stripslashes($_POST['title']));
$test = htmlentities(stripslashes($_POST['test']));
$allowedExtensions = array("gif", "png", "jpg","jpeg");

function watermarkImage($loaction)
{
	//laster inn bildet som skal settes på bildet :)
	$watermark = imagecreatefromgif("copyright.gif");
	$watermark_height = imagesy($watermark);
	$watermark_width = imagesx($watermark);
	
	$image = imagecreatetruecolor($watermark_width, $watermark_height);
	$image = imagecreatefromjpeg($location);
	
	$size = getimagesize($location);
	
	$x_pos = $size[0] - $watermark_width - 10;
	$y_pos = $size[1] - $watermark_height - 10;
	
	imagecopymerge($myfile, $watermark, $x_pos, $y_pos, 0, 0, $watermark_width, $watermark_height, 100);
	
	imagejpeg($myfile, $temp);
	
	imagedestroy($myfile);
	imagedestroy($watermark);
	}
	
function isAllowedExtension($fileName) {
  global $allowedExtensions;

  return in_array(end(explode(".", $fileName)), $allowedExtensions);
}

if (!$name){
	echo "<b><font style='font-family:Arial, Helvetica, sans-seri'>Vær så snill å velg en fil!<p>Du vill bli sendt tilbake!<br> Visst ikke trykk <a href='pictures.php'>her!</a></font>";
	echo '<meta http-equiv="refresh" content="4; pictures.php" />';
}else
{
	
	
	//Skjekker om bildet er tatt
	$check = mysql_query("SELECT * FROM pictures WHERE name='$name'");
	if (mysql_num_rows($check)>=1)
		die ("Username is taken!");
		else {
if ($error > 0)
{
    die("Error Uploading Image! Code $error.");
}
else
{
    if (isAllowedExtension($name)) //conditions for the file
    {
		watermarkImage("uploaded/$name");
        move_uploaded_file($temp,"uploaded/".$name);
		//setter inn dataen til databasen
$insert = mysql_query("INSERT INTO pictures VALUES ('','$title','$size','$name')") or die(mysql_error());
		echo "<title>$name er lagert</title><h4><center>Bildet er nå lagret på siden, du blir videresend om <b><span id='count'><b><</span> sekunder!<br>
		 visst ikke trykk  <a href=pictures.php> her </a></div></h4>";
		echo '<meta http-equiv="refresh" content="4; pictures.php" />';
    }
    else
    {
        die("formatet støttes ikke <meta http-equiv='refresh' content='2; pictures.php' />");
	}
}
		}
}

					  
?>
</div>
<div class="footer"><center><b>CopyRight 2010 allrights reservd Joakim Sjøhaug</b></center></div>

The page where file are being selected.

<?php include 'connect.php'; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="lightbox/js/prototype.js"></script>
<script type="text/javascript" src="lightbox/js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="lightbox/js/lightbox.js"></script>
<link rel="stylesheet" href="lightbox/css/lightbox.css" type="text/css" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Last opp et bilde</title>
<script type="text/javascript">
function show_alert()
{
alert("Bildet er slettet!");
}
function show_alert1()
{
alert("Bildet er slettet!");
}
</script>
<style type="text/css">

.bilder{
	width: 150;
	height: 170;
	padding-right: 15px;
	margin-bottom: 40px;
	font-family: Arial, Helvetica, sans-serif;
	color: #090;
	float: left;
	clear:right;}
.bilderdb {
	width: 825px;
	height: auto;
	clear: both;

}
.pages {
	width:800px;
	clear: both;
	padding-bottom: 20px;;
}
.siden1{
	vertical-align: middle;
	width: 825px;
	margin-left: auto;
	margin-right: auto;
	font-family: Arial, Helvetica, sans-serif;
	height: auto;
	padding-bottom:20px;
	padding-top:20px;}
.siden{
	vertical-align: middle;
	width: 825px;
	margin-left: auto;
	margin-right: auto;
	font-family: Arial, Helvetica, sans-serif;
	height: auto;
	padding-bottom: 20px;}
.footer{
	height: 30;
	width: auto;
	background-image:url(images/footer.png);
	font-family: Arial, Helvetica, sans-serif;
	color: #FFF;
	background-repeat: repeat-x;
	line-height: 2em;
	vertical-align:bottom;
	clear: both;}
.header{
	height: 100;
	width: auto;
	background-image:url(images/header.png);
	font-family: Arial, Helvetica, sans-serif;
	color: #FFF;
	line-height: 2em;}
</style>
</head>

<body link="#090" vlink="#090" alink="#00FF00">
<div class="header"><div class="siden"><img src="images/header_admin.png" align="left"></div></div>
<div class="siden">
<div class="siden1"><?php include 'scripts/menu.php'; ?></div>

<h2> Last opp bilder </h2>
<form action="upload.php" method="post" enctype="multipart/form-data">
	<input type="file" name="myfile" /><p>
    Om bildet, hva det er om osv.
    <input type="text" name="title" /><p>
    <input type="submit" value="Last opp" />
</form>

<h2> Bilder i databasen </h2>
<?php function delete_content($BildeId) {
                if(!$BildeId) {
                        return false;
                }else {
                        $BildeId = mysql_real_escape_string($BildeId);
                        $BildeInfoSQL = mysql_query("SELECT * FROM pictures WHERE id = '$BildeId'") or die (mysql_error());
                        $BildeInfo = mysql_fetch_assoc($BildeInfoSQL);
                        $BildeNum = mysql_num_rows($BildeInfoSQL);
                        
                        if($BildeNum > 0){
                            $BildeSlettSql = "DELETE FROM pictures WHERE id = '$BildeId'";
                            $BildeSlettSql = mysql_query($BildeSlettSql) or die(mysql_error());
                            unlink('uploaded/'.$BildeInfo['name']);
                        }else{
                            return false;
                        }
                        echo "Bildet er slettet";
						header ("Location: pictures.php");
                }
        }
?>
<div class="bilderdb">


<?php 
		if($_GET['delete']):
			delete_content($_GET['delete']);
		endif;
		?>

<?php
//max bilder på ver side
$per_page = 5;

//start
$start = $_GET['start'];

//Teller
$record_count = mysql_num_rows(mysql_query("SELECT * FROM pictures"));

//Mes sider
$max_pages = $record_count / $per_page; //kan komme som desimal tall

if (!$start)
	$start = 0;
	
//display data
$bilder = mysql_query("SELECT * FROM pictures ORDER BY id DESC LIMIT $start, $per_page") or die (mysql_error());

while ($row = mysql_fetch_assoc($bilder)) 
{
	
	
		//får info ut fra databasen
	$location = $row['name'];
	$id = $row['id'];
	$title = $row['title'];
	echo "<div algin='left' class='bilder'><a href='uploaded/$location' rel='lightbox [roadtrip]' title='$title'><img src='uploaded/$location'width='150' height='150'></a>
	<center><a href='?delete=$id' onclick='show_alert()'><b>Slett bilde</B></a></center><hr></div>";
}

// Neste og forgie knapper
$prev = $start - $per_page;
$next = $start + $per_page;

//show prev button
if (!($start<=0))
echo "<div class='pages'><a href='pictures.php?start=$prev'> Forgie side </a>";

//viser sider

//Value for føste side
$i=1;

for ($x=0;$x<$record_count;$x=$x+$per_page)
{	if ($start!=$x)
		echo "<a href='pictures.php?start=$x'>$i<a/> ";
	else
		echo "<a href='pictures.php?start=$x'><b>$i</b><a/>";
	$i++;
}
//show next buttno
if (!($start>=$record_count-$per_page))
echo "<a href='pcitures.php?start=$next'> Neste side </a></div>";
?></div>
<div class="footer"><center><b>CopyRight 2010 allrights reservd Joakim Sjøhaug</b></center></div>
</body>
</html>

Thanks for helping me!

Hi,

I think it's just a typo in the code.

function watermarkImage($loaction)
{
//laster inn bildet som skal settes på bildet :)
$watermark = imagecreatefromgif("copyright.gif");
$watermark_height = imagesy($watermark);
$watermark_width = imagesx($watermark);


$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = imagecreatefromjpeg($location);

Just change watermarkImage($loaction) to watermarkImage($location)
You used $loaction instead of $location

Kieran :)

commented: good spot +7

Where is $location defined?

Member Avatar for diafol
function watermarkImage($loaction)

This parameter cannot be accessed by $location. Good spot Kieran.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.