PHP无法移动上传的文件

时间:2015-03-11 09:43:19

标签: php upload ffmpeg

我一直在尝试创建upload.php脚本但是条件似乎不起作用,PHP无法将上传的文件移动到文件夹上传。

下面的Apache2日志输出

PHP Warning:  move_uploaded_file(): The second argument to copy() function cannot be a directory in /var/www/html/upload.php on line 18, referer: http://192.168.0.110/stream.php

PHP Warning:  move_uploaded_file(): Unable to move '/tmp/phpC34Agu' to '/var/www/html/upload/' in /var/www/html/upload.php on line 18, referer: http://192.168.0.110/stream.php

Upload.php代码

   <?php
$target_path = "/var/www/html/upload/";
$target = $target_path . basename($_FILES['uploadedfile']['name'][0] );
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'] [0], $target_path))
     { 
    echo "The file ". basename( $_FILES['uploadefile']['name'] [0]). " has been uploaded"; 
   } 
    else {
 echo "Sorry, there was a problem uploading your file."; 
     }
   ?>

我还希望php能够直接执行这个ffmpeg命令,但我不确定在哪里插入它。

FFMPEG命令

ffmpeg -re -i uploadedfile.name -vcodec copy -f mpegts udp://239.1.1.1:5000

感谢您的帮助。

亲切的问候,

Mark Couto

2 个答案:

答案 0 :(得分:0)

您需要指定文件的INDEX KEY

$ _ FILES [&#39;上传&#39;] [&#39; tmp_name的值&#39;]的 [0]

$target = $target . basename($_FILES["fileToUpload"]["name"][0]);
if(move_uploaded_file($_FILES['uploaded']['tmp_name'][0], $target))
{ 
    echo "The file ". basename( $_FILES['uploadedfile']['name'][0]). " has been uploaded"; 
} 

答案 1 :(得分:0)

这是问题所在的代码部分

      if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))  

$ _ FILES ['上传'] 应为$ _FILES ['FileToUpload']

试试这个

      if(move_uploaded_file($_FILES['FileToUpload']['tmp_name'], $target))  

&LT = http://php.net/manual/en/features.file-upload.post-method.php