2010-06-24 62 views
0

我上传从我自己的服务器上的文件,以soundcloud.com在PHP中使用的API文件:上传使用PHP

if (isset($mime)) { 
     $tmp_file = $tmp_path . $_FILES['file']['name']; 

     // Store the track temporary. 
     if (move_uploaded_file($_FILES['file']['tmp_name'], $tmp_file)) { 
      $post_data = array(
       'track[title]' => stripslashes($_POST['title']), 
       'track[asset_data]' => realpath($tmp_file), 
       'track[sharing]' => 'private' 
      ); 

      if ($response = $soundcloud->upload_track($post_data, $mime)) { 
       $response = new SimpleXMLElement($response); 
       $response = get_object_vars($response); 
       $message = 'Success! <a href="' . $response['permalink-url'] . '">Your track</a> has been uploaded!'; 

       // Delete the temporary file. 
       unlink(realpath($tmp_file)); 
      } else { 
       $message = 'Something went wrong while talking to SoundCloud, please try again.'; 
      } 
     } else { 
      $message = 'Couldn\'t move file, make sure the temporary path is writable by the server.'; 
     } 
    } else { 
     $message = 'SoundCloud support .mp3, .aiff, .wav, .flac, .aac, and .ogg files. Please select a different file.'; 
    } 
} 

这是我的代码。临时路径是http://122.166.23.38/dev3/bids4less/funkeymusic/upload 并且它具有权限777(-rwxrwxrwx)。

但它显示:

无法移动文件,确保临时路径是由服务器写入。

如何解决此问题?

+0

是你的服务器根目录下的临时目录? – Thariama 2010-06-24 11:39:08

+0

no root-> funkeymusic-> upload – rajanikant 2010-06-24 11:54:01

回答

3

我相信你在php中的临时路径应该指向你的服务器上的目录,而不是http位置。

+0

我已经给出了绝对路径为http://122.166.23.38/dev3/bids4less/funkeymusic/upload – rajanikant 2010-06-24 11:43:19

+1

@rajanikant你需要使用文件系统路径,而不是IP地址。 – 2010-06-24 11:49:49

+0

现在我正在使用文件系统路径,但给出相同的错误 – rajanikant 2010-06-25 06:43:32

0

什么是文件大小,以及它上传文件需要多长时间? 能否请您核实这些2的php.ini值:

  • 的max_execution_time
  • 的post_max_size

也许PHP的上传工具在某种程度上限制? PHP在safe_mode中吗?

+0

文件的大小是最大4 MB – rajanikant 2010-06-24 11:45:01

1

这个问题的例子太老了,但是因为它弹出反正...

你不必移动任何东西,也不会取消链接。 只是从它的临时位置读取上传的文件。

为了找出错误,将复杂的任务分割成更小的区块非常方便。尝试先发送静态文件,然后测试文件上传,然后才将这些任务加入最终应用程序。