[prev in list] [next in list] [prev in thread] [next in thread] 

List:       nyphp-talk
Subject:    Re: [nyphp-talk] I am about to pull my hair out over file uploads
From:       Werner <lists () mollentze ! co ! za>
Date:       2011-02-16 10:29:48
Message-ID: 4D5BA71C.8060903 () mollentze ! co ! za
[Download RAW message or body]

Hi Anthony

Your example code looks a bit sloppy, probably because you have changed it so 
much in order to try to make it work ;)

In either case, are you using the double quotes around your variables to 
type-cast them? Consider removing the quotes unless really necessary, or results 
might be unexpected, e.g. rather use curly braces for $_SESSION[sid]: 
"{$_SESSION[sid]}".

You mention that

The final variable (media) should contain the binary data of the file


In that case, the following code might be what one would expect to use?

$post = array(
     'cmd' => 'uploadmessage',
     'session' => $_SESSION[sid], // No need for double quotes
     'message_guid' => $msg_guid, // No need for double quotes
     'file_name' => "$file_name.mov",
     'media' => file_get_contents($target_path) // Assigning the binary file data
);

Also, purely judging from the variable name, it looks like $baseURL might be 
pointing to a local URI or only a URL fragment? Is that what was intended?

Regards,
Werner

On 16/02/2011 11:08, Anthony Papillion wrote:
> Hi Everyone,
>
> So I'm working with this new API and doing something that SHOULD be
> really, really simple. The API documentation says that I should pass
> parameters in a POST call They are:
>
> cmd
> session
> file_name
> message_guid
> media
>
> The final variable (media) should contain the binary data of the file
> I'm uploading through this call. I'm using cURL and the following code
> to perform the call to the API:
>
> post = array("cmd"=>"uploadmessage",
>                      "session"=>"$_SESSION[sid]",
>                      "message_guid"=>"$msg_guid",
>                      "file_name"=>"$file_name.mov",
>                      "media"=>"@$target_path",);
>
>                          $ch = curl_init();
>                          curl_setopt($ch, CURLOPT_HEADER, 0);
>                          curl_setopt($ch, CURLOPT_VERBOSE, 0);
>                          curl_setopt($ch, CURLOPT_POST, true);
>                          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
>                          curl_setopt($ch, CURLOPT_URL, $baseURL);
>                          curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
>
>
>                          $response = curl_exec($ch);
>
> A few notes:
>
> 1. the file is stored in a subdirectory called 'uploads' which is
> directly under the current directory the script is executing in. The
> variable $target_path will include the directory name and file name
> (which will vary). So an example of a $target_path value might be
> /uploads/myfile.mp4
>
> 2. Since I realize I *might* need to pass the full path to the file,
> I've tried replacing $target_path with something like
> /home/anthony/workspaces/appname/uploads/$filename and that didn't work
> either.
>
> For some reason, I am simply unable to upload this file! Isn't the code
> above *supposed* to work? Can anyone spot what's wrong? I've been
> wrestling with this little snippet of code for two days and Googleing my
> heart out. Help, please!
>
> Thank You,
> Anthony Papillion
> _______________________________________________
> New York PHP Users Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/Show-Participation
>

_______________________________________________
New York PHP Users Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

http://www.nyphp.org/Show-Participation
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic