duanguzhong5776 2014-06-30 19:42
浏览 32
已采纳

意外的T_OBJECT_OPERATOR(第59行)

I'm making a little project for somebody. Now i'm new to messing with files in php but i managed to get it to run on localhost using Mamp. Anyway, now i wanted to upload a test version online and when i'm trying to login i get the following error:

Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /home/fcom2126/public_html/bael/admin/overview.php on line 59

I have no idea what this error means, by searching around it could be a $ missing somewhere but i can't see where. Maybe you guys can help me out?

if (!in_array((new SplFileInfo($_FILES['afbeelding']['name']))->getExtension(), array('jpeg', 'jpg', 'png', 'gif'))) {
            exit('<p>Foute extentie. Enkel afbeeldingen toegelaten!</p>');
        } else {
            $path_parts = pathinfo($_FILES['afbeelding']['name']);
            $_FILES['afbeelding']['name'] = $name . "." . $path_parts['extension'];
            //!!! aanpassen bij UPLOAD
            $img = $_SERVER['DOCUMENT_ROOT'] ."/img/rouwregister/overledenen/". $_FILES['afbeelding']['name'];
        }

The if sentence is line 59, on my localhost i don't get any error but when trying it out on the web it does give me an error.

Where is my fault? Thanks beforehand

Pieter-Jan

EDIT

Could it be that SPL isn't supported in my php version yet?

  • 写回答

1条回答 默认 最新

  • dpgui8229808 2014-06-30 19:43
    关注

    Your localhost is running PHP5.4+ and your production server is running PHP5.3 or older. As a result you do not have access to class member access on instantiation:

    So this:

     (new SplFileInfo($_FILES['afbeelding']['name']))->getExtension()
    

    won't work. You need to change it to:

    $splFileInfo = new SplFileInfo($_FILES['afbeelding']['name'])
    $extension   = $splFileInfo->getExtension();
    if (!in_array($extension, array('jpeg', 'jpg', 'png', 'gif'))) {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值