Wrong upload_source value for remote uploads

enricodias4654

Member
YetiShare User
Jan 13, 2015
411
1
16
Files created by the remote upload feature are being created with upload_source = 'direct'. I guess the correct should be 'remote'.

Add this line after line 64 in /admin/tasks/process_remote_file_downloads.cron.php to correct this:
'upload_soure'=>'remote'

Obs: The last member of an array should not have a comma. In the files that I got here the array ends with a comma: 'max_file_size'=>UserPeer::getMaxUploadFilesize($userObj->level_id),

And I'm able to access this file via http and the task is executed. Add the following line in the top of the file (and in other tasks) to prevent its execution outside the cli:
if (php_sapi_name() != 'cli' && php_sapi_name() != 'cgi-fcgi') die('Out of CLI.');
 

adam

Administrator
Staff member
Dec 5, 2009
2,046
108
63
Thanks for pointing out the upload_source.

Obs: The last member of an array should not have a comma. In the files that I got here the array ends with a comma: 'max_file_size'=>UserPeer::getMaxUploadFilesize($userObj->level_id),
This isn't true, it's fine (and I'd say better practice) to use a comma on the last item. It'll cause issues in javascript but not PHP.
 

enricodias4654

Member
YetiShare User
Jan 13, 2015
411
1
16
I just checked the manual and using the last comma is a valid syntax. It's kinda weird and many other languages don't allow it, including javascript.
 

enricodias4654

Member
YetiShare User
Jan 13, 2015
411
1
16
I just find out that running fcgi will return cgi-fcgi in both CLI and web. This function should work:

function is_cli() {
return (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0)));
}

Also, the script doesn't seem to check if the user has available disk space when using the remote upload.
 

adam

Administrator
Staff member
Dec 5, 2009
2,046
108
63
function is_cli() {
return (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0)));
}
Unfortunately this wont work on every server, they wont all return 'cli' on php_sapi_name().

Code:
Also, the script doesn't seem to check if the user has available disk space when using the remote upload.
Yes it does.
 

enricodias4654

Member
YetiShare User
Jan 13, 2015
411
1
16
adam said:
Unfortunately this wont work on every server, they wont all return 'cli' on php_sapi_name().
Thats why the function also checks for $_SERVER['argc'], which only exists if the script is executed in cli.


adam said:
Yes it does.
The script checks if the user hasn't reached the maximum storage on their account when accepting the ajax request and sending the file to the queue. It doesn't check if the file size is bigger than the available storage space. The user is also able to put several files in the queue and even if the first file reach the maximum storage space, the others will still be downloaded.
 

adam

Administrator
Staff member
Dec 5, 2009
2,046
108
63
Thats why the function also checks for $_SERVER['argc'], which only exists if the script is executed in cli.
Why not just check for this in your code? :) The php_sapi_name() call is pointless then. I'll make a note to see if this can be limited to cli only on all servers but my experience of trying it before tends to be that it causes more issues than it's worth. At least to get it working in all environments.

The remote url will check filesize on each upload. So the first one indeed doesn't check for current filesize + available space, although once that is uploaded, any subsequent ones will not be permitted.
 

enricodias4654

Member
YetiShare User
Jan 13, 2015
411
1
16
I understand that different environments will have different values for php_sapi_name(). But the global $_SERVER['argc'] only exists if the script is executed in cli. The minimum value for argc is 1: http://php.net/manual/en/reserved.variables.argc.php

About the filesize, I think you didn't understand what I meant. The /core/page/url_upload_handler.ajax.php receives the ajax requests for the remote uploads. Every url will result in a request to this file. This file checks if the user have free storage space and then send the url to the queue to be downloaded. The problem is that the user can put dozens of urls in the textarea and they will all be send to the queue to be downloaded. Even if the first file of this queue uses all available space, the others will still be downloaded because they are still in the queue.
 

adam

Administrator
Staff member
Dec 5, 2009
2,046
108
63
Are you talking about the background url downloader? The one where you can close the browser?