I have a PHP script that uploads a document to Sharepoint using cURL. If I started a session in the terminal, the boot process will work fine.
As I would like to automatically call a script whenever this file has been modified, I use incron to detect the change in the appropriate folder and call the PHP script call.
My incron file looks like this:
/var/www/[further path]/temp IN_MODIFY,IN_CREATE /usr/bin/php /var/www/[further path]/uploadToSharepoint.php
When I look at syslog, I see that the script call was run correctly by incron. But for some reason, the file does not upload to Sharepoint. I also tried to create a file with global write permissions, but this did not solve my problem.
-rwxrwxrwx 1 www-data www-data 49058 Mรคr 3 10:28 [file].xlsx
Here is my script I'm calling:
enable '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 also tested it with a regular crontab, and that doesn't work either. It runs the script and passes through it without printing an error, but does not load the file. Is it possible that there is something to do with authentication?