Ik ben een programmeer leek maar heb een probleem met een scriptje waarvan ik hoop dat iemand me kan helpen.
Ik maak gebruik van een script dat inlogd op een bepaalde website en daar een bestand download en op mijn eigen server onder bepaalde naam weer opslaat.
Nu gaat dat goed zolang het een directe verwijzing is naar het bestand.
Maar nu moet ik vrijwel hetzelfde doen maar kan ik niet rechtstreeks naar het bestand verwijzen omdat deze dynamisch opgebouwd wordt en de naam dagelijks veranderd (zit een maand en datum in bestandsnaam.
Wel heb ik een vaste link die ervoor zorgt dat laatste bestand automatisch start met downloaden.
Dat werkt echter zolang ik die gewoon ind e browser open en het bestand dan naar mijn computer download.
Deze link ziet er als volgt uit:
http://domeinnaam.nl/wp-admin/admin.php?page=pmxe-admin-manage&id=1&action=get_file&_wpnonce=9caaead0e3
als ik het script met deze url als locatie van file aanroep via cron-job krijg ik de volgende foutmelding:
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file
het script is als volgt:
<?php
$remotefile = 'http://domeinnaam.nl/wp-admin/admin.php?page=pmxe-admin-manage&id=1&action=get_file&_wpnonce=9caaead0e3';
$localfile = '/home/wns/domains/domeinnaam.nl/public_html/feeds/bestandsnaam-test.csv'; // <-- Change this to an existing directory where to store the xml file
// This file is needed to save the session cookie
$scalacookie ='tmp/naamcookie.txt'; // <-- Change this to an existing directory to store a temporary file containing the cookie (cookie jar)
$loginUrl = "http://domeinnaam.nl/wp-admin";
// User name and password to login the website, a separate account can be create for this.
$user = 'gebruikersnaam'; // <-- put your login here
$pw = 'wachtwoord'; // <-- put your password here
//init curl
$ch = curl_init();
//Set the URL to work with
curl_setopt($ch, CURLOPT_URL, $loginUrl);
// ENABLE HTTP POST
curl_setopt($ch, CURLOPT_POST, 1);
//Set the post parameters
curl_setopt($ch, CURLOPT_POSTFIELDS, 'login_email='.$user.'&login_password='.$pw);
//Handle cookies for the login
curl_setopt($ch, CURLOPT_COOKIEJAR, $naamcookie);
//Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
//not to print out the results of its query.
//Instead, it will return the results as a string return value
//from curl_exec() instead of the usual true/false.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//execute the request (the login)
$store = curl_exec($ch);
//the login is now done and you can continue to get the
//protected content.
//set the URL to the protected file
curl_setopt($ch, CURLOPT_URL, $remotefile);
//execute the request
$content = curl_exec($ch);
// close session
curl_close($ch);
//save the data to disk
file_put_contents($localfile, $content);
?>
Iemand enig idee hoe ik dat kan oplossen zodat hij ook met die aanroep van te downloaden bestand werkt?
Groet
Daniel