将文件上载到位于服务器上的soundcloud

时间:2015-01-15 15:10:38

标签: php soundcloud

我想要做的是将一个mp3文件上传到IIS服务器上的地图。然后获取该文件并将其直接上传到我的soundcloud帐户。

我需要文件的绝对路径来上传文件。这给了我E:/ xxx / xxx / xxx。但我认为当代码检查它在我自己的电脑上检查的路径时,文件不在我的磁盘驱动器中。

所以我正在寻找一种方法将文件上传到我的soundcloud帐户&最好是直接上传我的上传地图。

编辑:换句话说,有没有办法将文件直接上传到我的soundcloud,类型="文件"选择

这是我到目前为止所获得的最新调试/测试文件:

    $target_dir = "..". DS . "database". DS . "tracks". DS;
    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
    $uploadOk = 1;
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

    // Check if file already exists
    if (file_exists($target_file)) {
        $error .= "Sorry, file already exists.<br />";
        $uploadOk = 0;
    }

    // Check file size
    if ($_FILES["fileToUpload"]["size"] > 5000000) {
        $error .= "Sorry, your file is too large.<br />";
        $uploadOk = 0;
    }
    // Allow certain file formats
    if($imageFileType != "mp3" ) {
        $error .= "Sorry, alleen mp3 is toegestaan.<br />";
        $uploadOk = 0;
    }

    // Check if $uploadOk is set to 0 by an error
    if ($uploadOk == 0) {
        echo "Sorry, your file was not uploaded.";
        echo $error;

    // if everything is ok, try to upload file
    //\\webserver\Websites\65647\database\tracks
    } else {
        if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
            echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";

            //$track_name = '@' . DS . DS . 'webserver' . DS . 'Websites' . DS . '65647' . DS . 'database'. DS . 'tracks' . DS . basename( $_FILES["fileToUpload"]["name"]);
            $track_name = '@' . $_SERVER['DOCUMENT_ROOT'] . DS . 'database'. DS . 'tracks' . DS . basename( $_FILES["fileToUpload"]["name"]);
            echo '@' . $_SERVER['DOCUMENT_ROOT'] . DS . 'database'. DS . 'tracks' . DS . basename( $_FILES["fileToUpload"]["name"]);

            try{        
                $track = json_decode($soundcloud->post('tracks', array(
                    'track[title]' => 'Test',
                    'track[asset_data]' => '@' . $_SERVER['DOCUMENT_ROOT'] . DS . 'database'. DS . 'tracks' . DS . basename( $_FILES["fileToUpload"]["name"])
                )));
                echo ' - '.$track['asset_data'];

            }catch(Services_Soundcloud_Invalid_Http_Response_Code_Exception $e){
                exit($e->getMessage());
            }

        } else {
            echo "Sorry, there was an error uploading your file.";
        }
    }

    <h3>Upload</h3>
    <form name="comment-form" method="post" action=""  enctype="multipart/form-data">
        <input type="file" name="fileToUpload"  />
        <br /><br />
        <input type="submit" value="submit" name="submit" />
    </form>

0 个答案:

没有答案