Jump to content

Archived

This topic is now archived and is closed to further replies.

kney

Fatal Error

Recommended Posts

I get this error: Fatal error: Call to undefined function uploadphoto() in ....... on line 39

 

I use phpFlickr to upload my photos from my website to Flickr.

Here's the code

 

<?php

include("includes/header.php");

if($_SESSION['usernr'] != true){

?>
<section id="content" class="body">
<h1>Sorry!</h1>
You are not authorized to view this page!
</section>
<?php

}else{

//Include phpFlickr
require_once("phpFlickr/phpFlickr.php");

$error=0;
$f = null;
if($_POST){
if(!$_POST['name'] || !$_FILES["file"]["name"]){
$error=1;
}else{
if ($_FILES["file"]["error"] > 0){
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}else if($_FILES["file"]["type"] != "image/jpg" && $_FILES["file"]["type"] != "image/jpeg" && $_FILES["file"]["type"] != "image/png" && $_FILES["file"]["type"] != "image/gif"){
$error = 3;
}else if(intval($_FILES["file"]["size"]) > 525000){
$error = 4;
}else{
$dir= dirname($_FILES["file"]["tmp_name"]);
$newpath=$dir."/".$_FILES["file"]["name"];
rename($_FILES["file"]["tmp_name"],$newpath);
//Instantiate phpFlickr
$status = uploadPhoto($newpath, $_POST["name"]);
if(!$status) {
$error = 2;
}
}
}
}

function uploadPhoto($path, $title) {
$apiKey = "*****************";
$apiSecret = "*****************";
$permissions = "write";
$token = "*****************";

$f = new phpFlickr($apiKey, $apiSecret, true);
$f->setToken($token);
return $f->async_upload($path, $title);
}
?>

<section id="content" class="body">
<div id="doc" class="yui-t7">
<div id="hd" role="banner"><h1>Foto Uploader</h1></div>
<div id="bd" role="main">
<div id="mainbar" class="yui-b">
<?php

if (isset($_POST['name']) && $error==0) {
echo " <h2>Your file is uploaded to <a href='http://www.flickr.com/photos/78262663@N02/' target='_blank'>DK1885 his photos!</a></h2>";
}else {
if($error == 1){
echo " <font color='red'>Please enter a file name.</font>";
}else if($error == 2) {
echo " <font color='red'>Your photo can't be uploaded.</font>";
}else if($error == 3){
echo " <font color='red'>Please only upload JPG, JPEG, PNG or GIF files.</font>";
}else if($error == 4){
echo " <font color='red'>The file size is larger than 512Kb.</font>";
}
?>
<h2>Upload your photos!</h2>
<form method="post" accept-charset="utf-8" enctype='multipart/form-data'>
<p>Name:   <input type="text" name="name" value="" ></p>
<p>Picture: <input type="file" name="file"/></p>
<p><input type="submit" value="Submit"></p>
</form>
<?php
}
?>
</div>
</div>
<div id="ft"></div>
</div>
</section>

<?php
}
include("includes/footer.php");

?>

Share this post


Link to post
Share on other sites

either your messing up the case in the function call or phpFicker.php does not contatin a function by the name of uploadphoto()

Share this post


Link to post
Share on other sites

functions are not case sensitive in php. uploadphoto is not defined.

Share this post


Link to post
Share on other sites

the uploadphoto() function is specified in this php file (7 lines below, from where I use it)

Share this post


Link to post
Share on other sites

functions are not case sensitive in php. uploadphoto is not defined.

 

I think you mean to say are case sensitive.

Share this post


Link to post
Share on other sites

yea i think he did, and I used

 

$status = uploadPhoto($newpath, $_POST["name"]);

 

and

 

function uploadPhoto($path, $title) {
}

Share this post


Link to post
Share on other sites

functions are not case sensitive in php. uploadphoto is not defined.

 

I think you mean to say are case sensitive.

 

No, I meant what I said. Functions are not case sensitive in PHP.

Share this post


Link to post
Share on other sites

So, with that out of the way, where is uploadPhoto() defined?

Share this post


Link to post
Share on other sites

Your function definition is inside an ELSE clause. PHP will NOT define that function until that section of code executes (since the function definition is conditional).  Move the function definition outside of your IF clause (recommended), or move the call to after the definition.

 

Also, indent your code, so you can easily see things like that.

 

Share this post


Link to post
Share on other sites
Your function definition is inside an ELSE clause.

 

Hmmm, I didn't even scroll down that far. Still, I'm amazed you bothered reading the code with the indentation the way it is.

Share this post


Link to post
Share on other sites

Your function definition is inside an ELSE clause. PHP will NOT define that function until that section of code executes (since the function definition is conditional).  Move the function definition outside of your IF clause (recommended), or move the call to after the definition.

 

Also, indent your code, so you can easily see things like that.

 

The code is indented on my host, but it didn't do the indentation when i copied it over.

That pretty much solves the issue.

Thanks mate!

 

<?php
include("includes/header.php");

function uploadPhoto($path, $title) {
	$apiKey = "******";
	$apiSecret = "******";
	$permissions = "write";
	$token = "******";

	$f = new phpFlickr($apiKey, $apiSecret, true);
	$f->setToken($token);
	return $f->async_upload($path, $title);
}

if($_SESSION['usernr'] != true){
?>
<section id="content" class="body">
<h1>Sorry!</h1>
You are not authorized to view this page!
</section>
<?php
}else{

//Include phpFlickr
require_once("phpFlickr/phpFlickr.php");

$error=0;
$f = null;
if($_POST){
if(!$_POST['name'] || !$_FILES["file"]["name"]){
	$error=1;
}else{
	if ($_FILES["file"]["error"] > 0){
		echo "Error: " . $_FILES["file"]["error"] . "<br />";
	}else if($_FILES["file"]["type"] != "image/jpg" && $_FILES["file"]["type"] != "image/jpeg" && $_FILES["file"]["type"] != "image/png" && $_FILES["file"]["type"] != "image/gif"){
		$error = 3;
	}else if(intval($_FILES["file"]["size"]) > 525000){
		$error = 4;
	}else{
		$dir= dirname($_FILES["file"]["tmp_name"]);
		$newpath=$dir."/".$_FILES["file"]["name"];
		rename($_FILES["file"]["tmp_name"],$newpath);
		//Instantiate phpFlickr
		$status = uploadPhoto($newpath, $_POST["name"]);
		if(!$status) {
		$error = 2;
		}
	}
}
}
?>

<section id="content" class="body">
<div id="doc" class="yui-t7">
<div id="hd" role="banner"><h1>Foto Uploader</h1></div>
<div id="bd" role="main">
<div id="mainbar" class="yui-b">
<?php

if (isset($_POST['name']) && $error==0) {
echo " <h2>Your file is uploaded to <a href='http://www.flickr.com/photos/78262663@N02/' target='_blank'>DK1885 his photos!</a></h2>";
}else {
if($error == 1){
	echo " <font color='red'>Please enter a file name.</font>";
}else if($error == 2) {
	echo " <font color='red'>Your photo can't be uploaded.</font>";
}else if($error == 3){
	echo " <font color='red'>Please only upload JPG, JPEG, PNG or GIF files.</font>";
}else if($error == 4){
	echo " <font color='red'>The file size is larger than 512Kb.</font>";
}
?>
<h2>Upload your photos!</h2>
<form method="post" accept-charset="utf-8" enctype='multipart/form-data'>
<p>Name:   <input type="text" name="name" value="" ></p>
<p>Picture: <input type="file" name="file"/></p>
<p><input type="submit" value="Submit"></p>
</form>
<?php
}
?>
</div>
</div>
<div id="ft"></div>
</div>
</section>

<?php
}
include("includes/footer.php");

?>

 

It's weird that the indentation gets done correct now..

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.