dtvfxzq3802
2015-03-10 18:59
浏览 185
已采纳

PHP注意:未定义的偏移量错误[重复]

This is my codes in compresser.php:

<?php

$filename = "isnotconverted_*";
$files = glob($filename);
$filefound = $files[0];

$new_filefound = str_replace( "isnotconverted_", '', $filefound );

$command = 'ffmpeg -i '.$filefound.' -b 64k -vf "movie=watermark.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:0 [out]" '.$new_filefound;
exec( $command );

unlink( $filefound );

When I open compresser.php directly there is no error and everything is OK, but when I use putty and type /usr/local/bin/php /home/dltvbourse/public_html/compresser.php, I get this error:

PHP Notice:  Undefined offset: 0 in /home/dltvbourse/domains/dl.tvbourse.ir/public_html/compresser.php on line 5
ffmpeg version 0.7.11, Copyright (c) 2000-2011 the FFmpeg developers
  built on Mar  1 2015 14:55:21 with gcc 4.1.2 20080704 (Red Hat 4.1.2-55)
  configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-shared --enable-libmp3lame --enable-libx264 --enable-libfaac --enable-libvorbis --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvpx
  libavutil    50. 43. 0 / 50. 43. 0
  libavcodec   52.123. 0 / 52.123. 0
  libavformat  52.111. 0 / 52.111. 0
  libavdevice  52.  5. 0 / 52.  5. 0
  libavfilter   1. 80. 0 /  1. 80. 0
  libswscale    0. 14. 1 /  0. 14. 1
  libpostproc  51.  2. 0 / 51.  2. 0
-b: No such file or directory
PHP Warning:  unlink(): No such file or directory in /home/dltvbourse/domains/dl.tvbourse.ir/public_html/compresser.php on line 12

What should I do?

</div>

图片转代码服务由CSDN问答提供 功能建议

此问题已经存在 这里有一个答案:

  • ”注意:未定义的变量“,”注意:未定义的索引“和”通知:未定义的偏移“使用PHP 28 answers

    这是我在compresser.php中的代码:

     &lt;?php 
     
     $ filename =“isnotconverted _ *”; 
     $ files = glob($ filename)  ; 
     $ filefound = $ files [0]; 
     
     $ new_filefound = str_replace(“isnotconverted_”,'',$ filefound); 
     
     $ command ='ffmpeg -i'。$ filefound。'  -b 64k -vf“movie = watermark.png [watermark]; [in] [watermark] overlay = main_w-overlay_w-10:0 [out]”'。$ new_filefound; 
    exec($ command); 
     
    unlink  ($ filefound); 
       
     
     

    当我直接打开 compresser.php 时,没有错误,一切正常,但是当我使用< code> putty 并输入 / usr / local / bin / php /home/dltvbourse/public_html/compresser.php ,我收到此错误:

      PHP注意:未定义的偏移量:0/5 / nffmpeg版本0.7.11 /home/dltvbourse/domains/dl.tvbourse.ir/public_html/compresser.php中的0  ,版权所有(c)2000-2011 FFmpeg开发人员建立于2015年3月1日14:55:21与gcc 4.1.2 20080704(Red Hat 4.1.2-55)
    配置: -  enable-gpl --enable  -version3 --enable-nonfree --enable-shared --enable-libmp3lame --enable-libx264 --enable-libfaac --enable-libvorbis --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-  libvpx 
     libavutil 50. 43. 0 / 50. 43. 0 
     libavcodec 52.123。  0 / 52.123。  0 
     libavformat 52.111。  0 / 52.111。  0 
     libavdevice 52. 5. 0 / 52. 5. 0 
     libavfilter 1. 80. 0 / 1. 80. 0 
     libswscale 0. 14. 1 / 0. 14. 1 
     libpostproc 51. 2。  0 / 51. 2. 0 
    b:没有这样的文件或目录
     
    NPP警告:unlink():第12行/home/dltvbourse/domains/dl.tvbourse.ir/public_html/compresser.php中没有这样的文件或目录 
       
     
     

    我该怎么办?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • du8794 2015-03-10 20:23
    已采纳

    You should run the php file in the correct folder. So do a:

    cd /home/dltvbourse/public_html/
    /usr/local/bin/php compresser.php
    

    (in putty or whatever ssh client you are using).

    The reason this fails is because glob() uses the current directory as offset directory. Since no files of the pattern are probably placed in the initial directory it won't work.

    Furthermore it is perhaps safe to rewrite your program a bit. After all it is always possible that something goes wrong and no such file is placed in the directory. In that case you probably better check the size of the array and throw an error message.

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题