0
  • just can't seem to get a result from a function called in its class...

    require_once($_SERVER['DOCUMENT_ROOT']."/youradmin_v2/scripts/php/IPTC.php");

    class Media{

    function Media() {
        // connects to db
    }
    
    function getMetaData($mediaID){
        global $select;
    
        $mediaDB = $select->mediaSelect($mediaID);
        $filePath=$mediaDB['filePath'];
    
        $itpc =new Image_IPTC($filePath);
        return $itpc->getTag($tag,0)." called?";
    }
    

    function newFileProcessing($file_name){ global $func;
    global $select, $insert, $update;

    $mediaID=$insert->addMedia($file_name, $filetype, $filePathImg,$testI);
    
    $mediaDB = $select->mediaSelect($mediaID);
    $filePath=$_SERVER['DOCUMENT_ROOT'].$mediaDB['pathToFile'];
    
    $update->updateQuery('media',"title='".$this->getMetaData($mediaID)."'");   
    

    }

    } $media = new Media;

when i use $media->getMetaData($mediaID) on a php page it works? No errors and when its called in the class " called?" is added to the entry so i think its somink to do with the $itpc =new Image_IPTC($filePath) part which can be viewed here;

iptc class

can anyone see what i'm doing wrong?! any pointers appreciated.

best, dan.

v3nt
  • 2,845
  • 6
  • 36
  • 50

1 Answers1

0
$this->getMetaData($mediaID)

is not going to work in the function newFileProcessing($file_name) because it is not a member function of the Media class

if your code looked like this it should work

require_once($_SERVER['DOCUMENT_ROOT']."/youradmin_v2/scripts/php/IPTC.php"); 

class Media{

    function Media() {
        // connects to db
    }

    function getMetaData($mediaID){
        global $select;

        $mediaDB = $select->mediaSelect($mediaID);
        $filePath=$mediaDB['filePath'];

        $itpc =new Image_IPTC($filePath);
        return $itpc->getTag($tag,0)." called?";
    }


    function newFileProcessing($file_name){
      global $func;   
      global $select, $insert, $update;   

      $mediaID=$insert->addMedia($file_name, $filetype, $filePathImg,$testI);

      $mediaDB = $select->mediaSelect($mediaID);
      $filePath=$_SERVER['DOCUMENT_ROOT'].$mediaDB['pathToFile'];

      $update->updateQuery('media',"title='".$this->getMetaData($mediaID)."'");   
   }
}

$media = new Media;
Tristan
  • 3,845
  • 5
  • 35
  • 58
  • thanks for getting back tristan. Not sure if i've been staring too hard but i can't see anything different in your code? best, Dan. – v3nt Sep 06 '10 at 16:08
  • how would i make newFileProcessing a member function of the Media class and what are the implications for it being called out of the class? cheers... – v3nt Sep 06 '10 at 16:09
  • the difference in code is that newFileProccessing is within the scope of the Media Class (look at the beginning and end of the braces between yours and mine) and their won't be any implications you should be able to call newFileProcessing like $media->newFileProcessing(fileName) – Tristan Sep 06 '10 at 16:12
  • ah - crap - that's a typo and it is actually in the class. – v3nt Sep 06 '10 at 16:17
  • I can't actually access that IPTC script you posted could that be what you experiencing? – Tristan Sep 06 '10 at 16:34
  • no - the script works. Another typo - http://oursite.modernactivity.co.uk/IPTC.txt – v3nt Sep 07 '10 at 07:41