NYCPHP Meetup

NYPHP.org

[nycphp-talk] I am about to pull my hair out over file uploads with cURL. Help!

Anthony Papillion papillion at gmail.com
Wed Feb 16 06:03:04 EST 2011


On 02/16/2011 04:29 AM, Werner wrote:
>
> Your example code looks a bit sloppy, probably because you have changed
> it so much in order to try to make it work ;)

That and an extreme lack of sleep. Unfortunately, that sloppiness has
infected a good part of my codebase over the last two days since I've
gone through it and changed things to try to get the code to work. A
cleanup job is definitely in order.

> 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]}".

No, I did not need to typecast my variables. Hadn't even noticed the
double quotes around them. They weren't there when I started this, I
swear! lol

> 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
> );

You're very right. THAT code seems to work with no problem at all. Well,
there *is* a problem, but I think it's on the server side as it seems to
think that there is no 'cmd' variable being passed. Yet, when I
print_r($post) I can clearly see that 'cmd' is being passed. Weird.  But
anyway, YOUR code does indeed work! Thank you for the corrections!

> 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?

Right. $baseURL has the HTTP address to the API (something like
www.sitename.com/api). I'm using that so I don't have to type out a long
site name over and over as this snippet is part of 9 different calls I
have to make to the API to get a file uploaded and operated on.

Again, thank you *very* much for the help. It is much appreciated. The
use of file_get_contents() never even entered my head and I totally
missed the double quotes.

Thanks!
Anthony



More information about the talk mailing list