• Content count

  • Joined

  • Last visited

  1. [PHP ]Uploading images from hard drive

    after struggling for many days I finally wrote a function that uploads a picture from the hard drive directly to the mercadolibre server, you can add it as a method to the meli class, even though it doesnt use the internal logic, i leave that as a TODO: public function upload_pic_from_harddrive($uploads_dir, $tmp_name, $name) { //$uploads_dir ----------> directory where the images are moved to after having been uploaded using an html5 form e.g.: "C:/xampp/htdocs/images"; //$tmp_name -----------> $_FILES['file']['tmp_name']; -----------------------> REPLACE 'file' with the value of the 'name' atribute in the html5 form //$name --------------------> basename($_FILES["file"]["name"]); ---------------------------> REPLACE 'file' with the value of the 'name' atribute in the html5 form $target_url = ''. $_SESSION['access_token']; move_uploaded_file($tmp_name, "$uploads_dir/$name"); $fname = "C:/xampp/htdocs/images/".$name; $cfile = new CURLFile(realpath($fname)); $post = array ( 'file' => $cfile ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $target_url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: multipart/form-data')); curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 100); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $result = curl_exec ($ch); if ($result === FALSE) { return "Error sending" . $fname . " " . curl_error($ch); curl_close ($ch); }else{ curl_close ($ch); return $result; } } I hope it helps somebody with the same problem. Cheers!!
  2. [PHP ]Uploading images from hard drive

    Thanks for your answer juvian! The problem is, I had already tried that, but the picture never shows. All i see is the "processing image" default image. The picture gets uploaded to the mercadolibre server (supposedly), since i get a 201 code when I examine the response. I also get the uploaded picture id and i'm able to retrieve the uploaded picture from the api. But there´s no way to see the picture. However if I use a picture already uploaded to certain public servers, the picture is visible inmeadiately. Last night I uploaded a picture directly from my hard drive using the code you mentioned and this morning still was "in process" so I take it that means it will never get uploaded. (I can´t wait 12 hours to upload a photo.) Here´s my code: //upload an image from the local hard drive to the mercadolibre server: $body2=array("source"=>"C:\xampp\htdocs\hgin\php-sdk-master\examples\logoHgin.jpg"); $response2 = $meli->post('/pictures', $body2, $params); //associate the recently uploaded picture to a previously created post $body3=array("id"=>"897268-MLA26367623449_112017", "max_size"=>"100*100"); $response3 = $meli->post('/items/MLA692059690/pictures', $body3, $params); Please note the part in bold, i'm using a file path, not an url because i'm trying to upload the pictures directly from the hard drive. Like i said i 'm able to do so, or at least both requests have a 201 response. But the picture never shows. Juvian, could you walk me through what I'm doing wrong? I need to upload the pictures directly from the hard drive. A million thanks in advance!!
  3. Hi! i 'm trying to post an item with pictures. I'm able to do so if i use public images that are hosted in some web pages Is it possible to use images from your own hard drive? without uploading them to a server? This is my code: $params = array('access_token' => $_SESSION['access_token']); $body = array("price" => '2', "title" => 'LOCAL 2ND TRIAL', "category_id"=> 'MLA40490', "currency_id"=>"ARS", "available_quantity"=>1, "condition"=>"used", "listing_type_id"=>"silver", "pictures"=>array(array("source"=>"C:\xampp\htdocs\logoHgin.jpeg")) ); $response = $meli->post('/items', $body, $params); It works perfectly if i replace the image url by a public one. The problem is i have hundreds of pics that i dont want to upload to a public server (it defeats the purpose of the app i'm writing). Is it possible to upload images directly from the hard drive?? Thanks in advance!!
  4. how to retrieve more than 200 items per request

    i already tried using offset, i have read the documentation. The question is weather its possible to retrieve more than 200 items per request. I guess that's the limit to not overwhlem the server or whatever. I benchmarked it and it takes around 3 seconds to retrieve 200 items, so it would require close to 17 hours to retrieve the 4 millons items in the books and magazines category. My question was how do i do to request more items faster, but i'm thinkig there isn´t really a way since the amount of data is huge.
  5. Hi I want to get all items in the books and magazines catagories from Argentina's site. I'm able to get a response but i only get (because of pagination) 200 items maximum. Is it possible to get all the items?(in this case there are 4 millions items, i know it's a lot.) Here´s my code: <?php require '../meliapp/Meli/meli.php'; $meli=new Meli(xxxxxxxxxx , xxxxxxxxxxxxxxxx); if (isset($_GET['code']) ): $oAuth = $meli->authorize($_GET['code'], 'http://localhost/meliapp/index.php'); if($oAuth['body']!==NULL || !empty($oAuth['body'])){ $_SESSION['access_token'] = $oAuth['body']->access_token; $_SESSION['token_type'] = $oAuth['body']->token_type; $_SESSION['expires_in'] = $oAuth['body']->expires_in; $_SESSION['scope'] = $oAuth['body']->scope; $_SESSION['user_id'] = $oAuth['body']->user_id; $_SESSION['refresh_token'] = $oAuth['body']->refresh_token; } endif; if(empty($_SESSION['access_token']) || !isset($_GET['code'])): echo "LOGIN NOW:<BR>"; echo '<a href="' . $meli->getAuthUrl('http://localhost/hgin/meliapp/index.php', Meli::$AUTH_URL['MLA']) . '">Login using MercadoLibre oAuth 2.0</a>'; endif; $params = array('category' => 'MLA3025', 'limit'=> '200'); $items = $meli->get('/sites/MLA/search', $params); The variable $items only holds 200 items. But i know from inspecting $items['body']->paging->total that there are 4 million items. Is there a way to get all 4 million items at once? or at least more than 200 items maximum per request. Thanks in advance!!!