kney Posted April 3, 2012 Share Posted April 3, 2012 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/260258-fatal-error/ Share on other sites More sharing options...
Muddy_Funster Posted April 3, 2012 Share Posted April 3, 2012 either your messing up the case in the function call or phpFicker.php does not contatin a function by the name of uploadphoto() Quote Link to comment https://forums.phpfreaks.com/topic/260258-fatal-error/#findComment-1333938 Share on other sites More sharing options...
trq Posted April 3, 2012 Share Posted April 3, 2012 functions are not case sensitive in php. uploadphoto is not defined. Quote Link to comment https://forums.phpfreaks.com/topic/260258-fatal-error/#findComment-1333944 Share on other sites More sharing options...
kney Posted April 3, 2012 Author Share Posted April 3, 2012 the uploadphoto() function is specified in this php file (7 lines below, from where I use it) Quote Link to comment https://forums.phpfreaks.com/topic/260258-fatal-error/#findComment-1333945 Share on other sites More sharing options...
Jessica Posted April 3, 2012 Share Posted April 3, 2012 functions are not case sensitive in php. uploadphoto is not defined. I think you mean to say are case sensitive. Quote Link to comment https://forums.phpfreaks.com/topic/260258-fatal-error/#findComment-1333950 Share on other sites More sharing options...
kney Posted April 3, 2012 Author Share Posted April 3, 2012 yea i think he did, and I used $status = uploadPhoto($newpath, $_POST["name"]); and function uploadPhoto($path, $title) { } Quote Link to comment https://forums.phpfreaks.com/topic/260258-fatal-error/#findComment-1333955 Share on other sites More sharing options...
trq Posted April 3, 2012 Share Posted April 3, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260258-fatal-error/#findComment-1333961 Share on other sites More sharing options...
trq Posted April 3, 2012 Share Posted April 3, 2012 So, with that out of the way, where is uploadPhoto() defined? Quote Link to comment https://forums.phpfreaks.com/topic/260258-fatal-error/#findComment-1333962 Share on other sites More sharing options...
DavidAM Posted April 3, 2012 Share Posted April 3, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260258-fatal-error/#findComment-1333965 Share on other sites More sharing options...
trq Posted April 3, 2012 Share Posted April 3, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260258-fatal-error/#findComment-1333969 Share on other sites More sharing options...
kney Posted April 4, 2012 Author Share Posted April 4, 2012 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.. Quote Link to comment https://forums.phpfreaks.com/topic/260258-fatal-error/#findComment-1334225 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.