PHP DropboxUploader.php does not work for huge files - php

I have the following PHP code that lets me back up files to Dropbox:
// Dropbox username/password
$dropbox_email = 'xxxxxxxxxx';
$dropbox_pass = 'xxxxxxxxxxx';
include('DropboxUploader.php');
$uploader = new DropboxUploader($dropbox_email, $dropbox_pass);
$uploader->upload('backup-images.php','Backup/');
$uploader->upload($zipArchiveName,'Backup/');
File backup-images.php is around 1kb while $zipArchiveName is around 400Mb. I seem to mange to upload backup-images.php but not $zipArchiveName.
I tried using
ini_set('max_execution_time', 0);
ini_set('memory_limit', '-1');
I also tried modifying php.ini i.e. max_execution_time and the memory_limit but I can't seem to upload the huge file to dropbox. I have ample of space on my dropbox account.
In my case I donot wish to use the Dropbox SDK but DropboxUploader.php found here.
I'd like suggestions or reasons why this isn't working or ideas how to get around it.

One way you can go around this issue by splitting your backup file into multiple files. TAR archiver has a way to create multi-part archives. Take a look: https://unix.stackexchange.com/questions/21373/can-i-automate-tars-multi-volume-feature

There is a constant in that class that provides upload size limit at this line:
const DROPBOX_UPLOAD_LIMIT_IN_BYTES = 314572800;
This is 300MB. So this class should throw an Exception in the following portion of code for a 400MB file:
$filesize = filesize($source);
if ($filesize < 0 or $filesize > self::DROPBOX_UPLOAD_LIMIT_IN_BYTES) {
throw new Exception("File '$source' too large ($filesize bytes).", self::CODE_FILESIZE_TOO_LARGE);
}
Are you not seeing this this Exception in error logs?
I don't know if that is the true current limit for this Dropbox API. You may want to check their documentation to see if you can bump up the max size constant.

Related

Try upload videofile

I use Laravel 5.4 and I try upload video file. Image file upload successfully.
$video = Request::file('video_file')) {
$fullName = 'videos/'.uniqid().time().'.'.$video->getClientOriginalExtension();
Storage::disk()->put($fullName, $video);
But it didn't work. When I try get information about file - size = 0
What I do wrong?
There’s a limit on the amount of data you can send in a POST request. If you exceed that limit, PHP will return zero as the size of the file.
Instead, you’ll need to upload the file in chunks. If you’re using something like Amazon Web Services, they have a JavaScript SDK that will handle multi-part uploads for you: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property
Check out http://php.net/manual/en/ini.core.php#ini.post-max-size
PHP has a default max_post_size of 8mb I believe, anything larger than that will not go through. There is also a upload_max_filesize that you may want to check out. I'm not sure if increasing the limit is the correct answer here, as I'm not sure what complications that would bring. When we upload large Files we use blue imp's file uploader: https://github.com/blueimp/jQuery-File-Upload
It's pretty straight forward and automatically chunks the uploads for you.

Cannot optimize image in PHP

This is the code I have:
$from = ...; // original uploaded file
$target = ...; // save path for optimized file
#unlink($target); // removes file if already exists
$image_o = imagecreatefromjpeg($from); // get a file
imagejpeg($image_o, $target, 85); // save optimized
imagedestroy($image_o); // free memory
But it doesn't do anything. This is going in loop, but now I test it on the single file. Seems to be working on smaller files. I tried image with size ~120 kB and optimized OK. But file with more than 1 MB, it will do nothing and those are files I really need to optimize. I also tried this:
set_time_limit(6000);
ini_set('memory_limit', '200M');
But no help. I'm working on a shared hosting, so I have no access to the php.ini or to install 3rd party PHP extension. Is there an alternative for imagecreatefromjpeg which seems to be the problem?

eajaxupload for Yii always "failed"

We are currently trying to use the extension eajaxupload for Yii but it seems to be outputting failed everytime we try to upload a file.
We have tried
a) editing the file / minimum file sizes
b) playing around with the file path (may still be incorrect, if anyone knows what the path for locally using in xampp would be, let us know. Our uploads folder is in the root of the project.)
c) changing the htiaccess php file
d) permissions
we just don't know if the code itself is appearing wrong.
controller
/* UPLOADER */
public function actionUpload(){
Yii::import("ext.EAjaxUpload.qqFileUploader");
// $folder = '/uploads/';
// $folder=Yii::getPathOfAlias() .'/upload/';
$folder=Yii::app()->baseUrl . '/uploads/';
$allowedExtensions = array("jpg","png");//array("jpg","jpeg","gif","exe","mov" and etc...
$sizeLimit = 10 * 1024 * 1024;// maximum file size in bytes
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload($folder);
// $return = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
//
// $fileSize=filesize($folder.$result['filename']);//GETTING FILE SIZE
// $fileName=$result['filename'];//GETTING FILE NAME
//
// echo $return;// it's array
$result = $uploader->handleUpload($folder);
$fileSize=filesize($folder.$result['filename']);//GETTING FILE SIZE
$fileName=$result['filename'];//GETTING FILE NAME
$result=htmlspecialchars(json_encode($result), ENT_NOQUOTES);
echo $result;// it's array
}
View
*$this->widget('ext.EAjaxUpload.EAjaxUpload',
array(
'id'=>'uploadFile',
'config'=>array(
'action'=>'/upload/',
// 'action'=>Yii::app()->createUrl('controllers/uploads/'),
'allowedExtensions'=>array("jpg","png"),//array("jpg","jpeg","gif","exe","mov" and etc...
'sizeLimit'=>10*1024*1024,// maximum file size in bytes
//'minSizeLimit'=>10*1024*1024,// minimum file size in bytes
'onComplete'=>"js:function(id, fileName, responseJSON){ alert(fileName); }",
'messages'=>array(
'typeError'=>"{file} has invalid extension. Only {extensions} are allowed.",
'sizeError'=>"{file} is too large, maximum file size is {sizeLimit}.",
'minSizeError'=>"{file} is too small, minimum file size is {minSizeLimit}.",
'emptyError'=>"{file} is empty, please select files again without it.",
'onLeave'=>"The files are being uploaded, if you leave now the upload will be cancelled."
),
'showMessage'=>"js:function(message){ alert(message); }"
)*
I got the same problem long ago.
You have to make sure that:
you get the local path, not url (Yii::getPathOfAlias('webroot')).
the $sizeLimit has to be less than the php options 'post_max_size' and 'upload_max_size'. You can check their values with ini_get(variable) and convert it to Bytes.
Also noticed that you are trying to upload the file twice.
If none of them work post the error message that you are getting.
It seems to me that your action is wrong in the
'config'=>array(
'action'=>'/upload/',
If you are uploading to the public function actionUpload()
then your action must be 'upload/upload' because the ConrollerName/ActionName must match the 'action' in your widget
'config'=>array(
'action'=> Yii::app()->baseUrl . '/upload/upload',
or
'config'=>array(
'action'=>$this->createUrl('upload/upload')
Take a look at this too: http://www.yiiframework.com/doc/guide/1.1/en/topics.url
Good luck
To update this, it wouldn't work on local server Xampp on MAC.
It worked on our live dev server, but not the live server. Seems the extension is server dependant. There is a lack of documentation and I imagine there is a fix, but it answers a lot of questions how the code is fine but not working.

Request Entity Too Large with small files

I know there are many questions about Request Entity Too Large on internet but i could not find right answer for my problem ;)
I`m using HTML file input tag to let users upload their images .
<input type = 'file' class = 'upload-pic' accept='image/*' id ='Fuploader' name = 'pro-pic'><br>
There is nothing wrong with files less than 2 MB which is allowed by my site
But the problem is if some one decide to upload larger file like 5.10 MB , i can handle it by php and warn user that this file is too large
if($_FILES['pro-pic']['size'] > 2000000)
{
die("TOO LARGE");
}
But my problem is by uploading 5.10 MB file , Request entity too large error will be lunched and rest of my php code won`t work
I have checked post_max_size and upload_max_filesize they are both set to 8MB
But i get Error on 5.10MB !
And I need to find way to handle files even larger than 8MB because there is no way to guess what user may try to upload ;) and i don`t want them to get dirty and broken page because of REQUEST ENTITY TOO LARGE ERROR
Is there any way too fully disable this Error Or set upload_max_filesize and post_max_size to infinity ?
You need to set SecRequestBodyAccess Off.
Check the link i have given ..it would help you
https://serverfault.com/questions/402630/http-error-413-request-entity-too-large

is it possible to limit the size of uncompressed zipped files in unix?

i am implementing a service where i have to extract a zip file which was uploaded by a user.
in order to avoid disk overflow, i have to limit BOTH zip file size AND unzipped files size.
is there anyway to do that (check unzipped files size) BEFORE unzipping?
(for security reasons).
i am using unix, called from a PHP script.
Since you're working in PHP, use its ZipArchive library.
$zip = zip_open($file);
$extracted_size = 0;
while (($zip_entry = zip_read($zip))) {
$extracted_size += zip_entry_filesize($zip_entry);
if ($extracted_size > $max_extracted_size) {
// abort
}
}
// do the actual unzipping
You might want to put a limit on the number of files as well, or add a constant amount per file, to take into account the size of the metadata for each file. While you can't easily get a precise figure for that, adding a few hundred bytes to a couple of kilobytes per file is a reasonable estimate.

Categories