douyuai8994
2015-09-07 12:36
浏览 71
已采纳

试图用PHP重命名两个文件

I'm using Ubuntu 12.04, apache2 + nginx (ISPManager)

My server works with Wowza Media Server, and that server put my recorded .flv videos in {root-of-the-server}/movies

I recieve the name of video from $_GET['rfile'] of the action: $this->request->get('rfile').

The file is created in the folder successfully, I locate it in two ways:

file_get_contents('http://<ip, which sends to {root-of-the-server}>/movies/'.$this->request->get('rfile'));

or

`find /movies/ -name $rfile`;

To upload my rec videos from the Wowza folder to web-site, I'm trying to rename the file after the recording is stopped:

From
'{root-of-the-server}/movies/$this->request->get('rfile').flv'
To
'.$_SERVER['DOCUMENT_ROOT'].'/upload/resume/resume'.$item['id'].'.flv'

I use $_SERVER['DOCUMENT_ROOT'], because I need to move the recorded videos automatically, and on the several websites.

Note: I don't put the {root-of-the-server} in my actual script, that's just a placeholder for posting here.

I'm trying to rename this with PHP.
First try:
shell_exec('mv /movies/'.$this->request->get('rfile').''.$_SERVER['DOCUMENT_ROOT'].'/upload/resume/resume'.$item['id'].'.flv');
Second try:
mv /movies/$rfile /movies/ok-just-rename-it-plz.flv
Third try:
rename('http://95.183.8.96:81/'.$this->request->get('rfile'), 'http://95.183.8.96:81/'.$item['id'].'.flv');
Fourth try:
rename('/movies/'.$this->request->get('rfile'), '/upload/resume/resume'.$item['id'].'.flv');

However none of these attempts worked. How can I rename these two files with a http wrapper? Or how can I rename them in another way?

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

我正在使用Ubuntu 12.04,apache2 + nginx(ISPManager)

我的服务器与Wowza Media Server配合使用,该服务器将录制的 .flv 视频放入 {root-of-the-server} / movies \ n

我收到了来自 $ _ GET ['rfile'] 的视频名称: $ this-&gt; request-&gt; get('rfile')

文件在文件夹中成功创建,我以两种方式找到它:

  file_get_contents('http://  &lt; ip,发送到{root-of-the-server}&gt; / movies /'.$ this-&gt; request-&gt; get('rfile')); 
    
 
 

 `find / movies / -name $ rfile`; 
   
 
 

要将我的录制视频从Wowza文件夹上传到网站,我正在尝试在录制停止后重命名文件:

来自
'{ 请求 - &GT;;获得( '的RFile')FLV '结果, 要结果, <代码>' $ _ SERVER /电影/ $这 - &GT根的最服务器} [ 'DOCUMENT_ROOT']。 '/上传/恢复/恢复'。$ item ['id']。'。flv'

我使用 $ _ SERVER ['DOCUMENT_ROOT'] ,因为我需要移动录制的 视频自动,并在几个网站上。

注意:我没有把 {root-of-the-server} 放在我的实际脚本中,那是 只是一个占位符,可以在这里发布。

我正在尝试用PHP重命名。
首先尝试:
shell_exec('mv / movies / ” $这个 - &GT;请求 - &GT;获得( '的RFile')。 '' $ _ SERVER [ 'DOCUMENT_ROOT'] '/上传/恢复/简历' $项[ '身份证'] 'FLV。'。 );
第二次尝试:
mv / movies / $ rfile /movies/ok-just-rename-it-plz.flv
第三次 尝试:
重命名('http://95.183.8.96:81/'.$this->request->get('rfile'),'http://95.183.8.96: 81 /'.$ item ['id']。'。flv');
第四次尝试:
rename('/ movies /'.$ this-&gt; request-&gt; get('rfile'),'/ upload / resume /resume'.$item ['id']。'。flv') ;

nn

但是 这些尝试都没有奏效。 如何使用http包装器重命名这两个文件? 或者我如何以其他方式重命名它们?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doumiang2297 2015-09-07 22:52
    已采纳

    My problem of these days was in open_basedir of ISPmanager (open_basedir is turned on by default). I went to /etc/apache2/apache2.conf and made these changes:

    <Directory /var/www/USER/data/www/WEBSITE> php_admin_value open_basedir "/movies:/var/www/USER/data:." </Directory>

    instead of

    <Directory /var/www/USER/data/www/WEBSITE> php_admin_value open_basedir "/var/www/USER/data:." </Directory>

    Anyway, thanks to Kevin Nagurski for answer :33

    点赞 打赏 评论
  • dro59505 2015-09-07 13:08

    rename is what you need. If it were possible over HTTP, you'd have a major security hole, so stick to the absolute paths. Make sure your destination directory is writable with PHP:

    echo is_writable($_SERVER['DOCUMENT_ROOT'] . '/upload/resume/resume') ? 'yup' : 'nope';
    

    Also check to make sure the source file actually exists:

    echo file_exists('/movies/' . $this->request->get('rfile')) ? 'yup' : 'nope';
    

    And that you have permission to read it:

    echo is_readable('/movies/' . $this->request->get('rfile')) ? 'yup' : 'nope';
    

    If any of these fail, you have a permissions issue that you need to rectify with a bit of chmod or chown.

    点赞 打赏 评论

相关推荐 更多相似问题