skyzyx
4/3/2013 - 3:18 AM

Guzzle isn't saving the files to the temp directory.

Guzzle isn't saving the files to the temp directory.

<?php

# Namespaces
use Guzzle\Http\Client;
use Symfony\Component\Filesystem\Filesystem;

# Instantiate
$http = new Client();
$fs = new Filesystem();

# Create temp directory
$tmp = sys_get_temp_dir() . '/my-app';
$fs->mkdir($tmp);

# Fetch
$request = $http->get('http://example.com/results.json');
$many_results = $request->send()->json();

# Collect
$queue = array();
foreach ($many_results as $one_result)
{
    $id = $one_result['id'];
    $path = $tmp . "/${id}.jpg";

    # !!!
    $this->queue[] = $http->get($one_result['photo_url'], null, fopen($path, 'w+'));
}

# Execute
$http->send($queue);

#---------------------------------------------------------------------------
# $tmp directory is created, and full of zero kb files.
#---------------------------------------------------------------------------