无法从其类内调用函数,但可以吗?

发布于 2024-09-17 09:02:46 字数 1124 浏览 2 评论 0原文

  • 似乎无法从其类中调用的函数获得结果...

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

    媒体类{

    函数媒体() {
        // 连接到数据库
    }
    
    函数 getMetaData($mediaID){
        全局$选择;
    
        $mediaDB = $select->mediaSelect($mediaID);
        $filePath=$mediaDB['filePath'];
    
        $itpc =new Image_IPTC($filePath);
        return $itpc->getTag($tag,0)." 被调用?";
    }
    

    函数newFileProcessing($file_name){ 全局 $func;
    全局 $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 = 新媒体;

当我在 php 页面上使用 $media->getMetaData($mediaID) 时它可以工作吗?没有错误,当它在“调用?”类中调用时添加到条目中,所以我认为它与 $itpc =new Image_IPTC($filePath) 部分有关,可以在此处查看;

iptc 类

任何人都可以看到我做错了什么吗?!任何指示表示赞赏。

最好的,丹。

  • 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仲春光 2024-09-24 09:02:46
$this->getMetaData($mediaID)

不会在函数 newFileProcessing($file_name) 中工作,因为它不是 Media 类的成员函数,

如果您的代码看起来像这样,它应该可以工作

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;
$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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文