Search code examples
phpfile-uploadpodio

Podio PHP API, file doesn't upload, no errors


I'm trying to do something with Podio API, I'm a beginner. So my code is:

PodioItem::create($app_id, array('fields' => array(
"title" => ($name . " " . $surname),
"adres-e-mail-2" => $email,
), 
array("file_ids" => $file->id) ));

Item is created without problems, but without a file uploaded. Error log throws only deprecation:

PHP Deprecated: curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead in /home/avat/public_html/avat/aiesec/test/podio/lib/Podio.php on line 179

File upload script is working, I can save it to my folder. I have Podio file ID working. I don't really know where to look for errors now.


Solution

  • It's almost always easier to work with objects rather than the static methods. As for uploading a file I've broken the example below out in sections so it's easier to see what's going on:

    // Upload file
    $file = PodioFile::upload("/Users/andreas/Desktop/irwin.jpg", "irwin.jpg");
    
    // Create a new item object
    $item = new PodioItem(array(
      'app' => new PodioApp(8018420),
      'fields' => new PodioItemFieldCollection()
    ));
    
    // Set a value for the field with the external id 'title'
    $item->fields['title'] = new PodioTextItemField();
    $item->fields['title']->values = $name . " " . $surname;
    
    // Create a new collection for files and add the $file to this collection
    $item->files = new PodioCollection(array($file));
    
    // Save the item to Podio
    $item->save();
    

    See more at: