I have a PHP script that uploads a document on a Sharepoint using cURL. If I run the scipt in the terminal, the upload process works fine.
As I would like to automatically call the script whenever this file is changed, I use incron to detect a change in the respective folder and trigger the call of the PHP script.
My incron file looks like the following:
/var/www/[further path]/temp IN_MODIFY,IN_CREATE /usr/bin/php /var/www/[further path]/uploadToSharepoint.php
When I have a look at the syslog, I can see that the script call has been triggered correctly by incron. But for some reasons, the file is not uploaded to the Sharepoint. I also tried to create the file with global write permissions, but this didn't solve my problem.
-rwxrwxrwx 1 www-data www-data 49058 Mär 3 10:28 [file].xlsx
Here is my script I'm calling:
include 'database.php';
$username="[username]";
$password="[password]";
$localFileURL="/var/www/[further path]/temp/";
$files = scandir($localFileURL, 1);
$newest_file = $files[0];
$pathToUpload=getTeamPath($newest_file);
uploadDocument($pathToUpload . '/' . $newest_file, $localFileURL . $newest_file,$username, $password);
function uploadDocument($dest, $localFile,$username, $password){
$fp = fopen($localFile, 'r');
// Connecting to website.
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt($ch, CURLOPT_URL, $dest);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 86400); // 1 Day Timeout
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localFile));
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_exec ($ch);
if (curl_errno($ch)) {
$msg = curl_error($ch);
}
else {
$msg = 'File uploaded successfully.';
}
curl_close ($ch);
}
I would really appreciate any help!!!
EDIT: I have also teste it with a normal crontab now and this doesn't work either. It does execute the script and loops through it without printing an error, but doesn't upload the file. Is it possible that is has somethin to do with the authentication?