douyuai8994
douyuai8994
2015-09-07 12:36

试图用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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • doumiang2297 doumiang2297 6年前

    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 dro59505 6年前

    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.

    点赞 评论 复制链接分享

相关推荐