views:

80

answers:

4

I am uploading a file to soundcloud.com from my own server with using an API in 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.';
    }
}

This is my code. The temp path is http://122.166.23.38/dev3/bids4less/funkeymusic/upload and it has permissions 777 (-rwxrwxrwx).

But it shows:

Couldn't move file, make sure the temporary path is writable by the server.

How do I fix this problem?

+3  A: 

I believe your temp path in php should point to a directory on your server, not a http location.

Redlab
i have given obsolute path as http://122.166.23.38/dev3/bids4less/funkeymusic/upload
rajanikant
@rajanikant you need to use a filesystem path, not an IP address.
Pekka
now i am using file system path but give same error
rajanikant
A: 

What's the file size, and how long takes it to upload the file? Can you please verify those 2 php.ini values:

  • max_execution_time
  • post_max_size

Maybe PHP's upload facility is constrained in some way? Is PHP in safe_mode?

tweber
size of file is max 4 mb
rajanikant
A: 

TRY S_SERVER you will get brief description from this url http://php.net/manual/en/reserved.variables.server.php

Here is the example given to find address for your server

try big example to sort out you method

Wasim
+1  A: 

This question is too old, but as it were popped anyway...

You don't have to move anything, nor unlink. Just read uploaded file from it's temporary location.

And it comes extremely handy to split your complex task into smaller chunks, in order to locate an error. Try to send a static file first, then test file upload, and only then join these tasks into final application.

Col. Shrapnel