Skip to content

Commit

Permalink
update class.upload.php to v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dleffler committed Oct 15, 2021
1 parent 90c39b4 commit be5082c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
4 changes: 2 additions & 2 deletions external/ExtPrograms.csv
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Twitter model,2.3.1,github.com/tijsverkoyen/TwitterOAuth,2.3.1,placed in Twitter
Twitter API,1.0.6,github.com/J7mbo/twitter-api-php,1.0.6,used by socialmedia module
SimplePie,1.5.6,github.com/simplepie/simplepie,1.5.6,php 8 fix
pixidou,0.1exp,github.com/asvinb/pixidou,0.1,"placed in Pixidou module, heavily modified at this point"
class.upload,1.0.8,github.com/verot/class.upload.php,"1.0.8/2.1.0
class.upload,2.1.0,github.com/verot/class.upload.php,"2.1.0
","Correct flip operation where flip vertical & horizontal were inverted/swapped, php 8 fix"
iCalCreator,2.28.2,github.com/iCalcreator/iCalcreator,2.30.5/2.40.0,uncomment load utilities; php 8 fix
iCalCreator,2.28.2,github.com/iCalcreator/iCalcreator,2.40.0,uncomment load utilities; php 8 fix
scssphp,1.8.1exp,github.com/scssphp/scssphp,1.8.1,includes example server; hack to compile newui
lessphp,0.5.0exp,github.com/leafo/lessphp,0.5.0,"will not compile bootstrap v3+, hack to allow prefix"
less.php,3.1.0exp,github.com/wikimedia/less.php,3.1.0,"code edit to fix IIS compatibility, php v5.6 fix"
Expand Down
36 changes: 24 additions & 12 deletions external/class.upload/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ It is the ideal class to quickly integrate file upload in your site. If the file

You can also use the class to work on local files, which is especially useful to use the image manipulation features. The class also supports Flash uploaders and XMLHttpRequest.

The class works with PHP 5.3+ and PHP 7 (use version 1.x for PHP 4 support), and its error messages can be localized at will.
The class works with PHP 5.3+, PHP 7 and PHP 8 (use version 1.x for PHP 4 support), and its error messages can be localized at will.


## Install via composer
Expand Down Expand Up @@ -56,7 +56,7 @@ Create a simple HTML file, with a form such as:
```
Create a file called upload.php (into which you have first loaded the class):
```php
$handle = new upload($_FILES['image_field']);
$handle = new \Verot\Upload\Upload($_FILES['image_field']);
if ($handle->uploaded) {
$handle->file_new_name_body = 'image_resized';
$handle->image_resize = true;
Expand Down Expand Up @@ -87,14 +87,26 @@ If you don't set any processing parameters and call `process()` just after insta

Don't forget to add `enctype="multipart/form-data"` in your form tag `<form>` if you want your form to upload the file.

### Namespacing

The class is now namespaced in the `Verot/Upload` namespace. If you have the error *Fatal error: Class 'Upload' not found*, then make sure your file belongs to the namespace, or instantiate the class with its fully qualified name:

```php
namespace Verot\Upload;
$handle = new Upload($_FILES['image_field']);
```
or

```php
$handle = new \Verot\Upload\Upload($_FILES['image_field']);
```

### How to process local files?

Instantiate the class with the local filename, as following:

```php
$handle = new upload('/home/user/myfile.jpg');
$handle = new Upload('/home/user/myfile.jpg');
```


Expand All @@ -103,44 +115,44 @@ $handle = new upload('/home/user/myfile.jpg');
Instantiate the class with the special _php:_ keyword, as following:

```php
$handle = new upload('php:'.$_SERVER['HTTP_X_FILE_NAME']);
$handle = new Upload('php:'.$_SERVER['HTTP_X_FILE_NAME']);
```

Prefixing the argument with _php:_ tells the class to retrieve the uploaded data in _php://input_, and the rest is the stream's filename, which is generally in `$_SERVER['HTTP_X_FILE_NAME']`. But you can use any other name you see fit:

```php
$handle = new upload('php:mycustomname.ext');
$handle = new Upload('php:mycustomname.ext');
```

### How to process raw file data?

Instantiate the class with the special _data:_ keyword, as following:

```php
$handle = new upload('data:'.$file_contents);
$handle = new Upload('data:'.$file_contents);
```

If your data is base64-encoded, the class provides a simple _base64:_ keyword, which will decode your data prior to using it:

```php
$handle = new upload('base64:'.$base64_file_contents);
$handle = new Upload('base64:'.$base64_file_contents);
```

### How to set the language?

Instantiate the class with a second argument being the language code:

```php
$handle = new upload($_FILES['image_field'], 'fr_FR');
$handle = new upload('/home/user/myfile.jpg', 'fr_FR');
$handle = new Upload($_FILES['image_field'], 'fr_FR');
$handle = new Upload('/home/user/myfile.jpg', 'fr_FR');
```

### How to output the resulting file or picture directly to the browser?

Simply call `process()` without an argument (or with null as first argument):

```php
$handle = new upload($_FILES['image_field']);
$handle = new Upload($_FILES['image_field']);
header('Content-type: ' . $handle->file_src_mime);
echo $handle->process();
die();
Expand All @@ -149,7 +161,7 @@ die();
Or if you want to force the download of the file:

```php
$handle = new upload($_FILES['image_field']);
$handle = new Upload($_FILES['image_field']);
header('Content-type: ' . $handle->file_src_mime);
header("Content-Disposition: attachment; filename=".rawurlencode($handle->file_src_name).";");
echo $handle->process();
Expand Down Expand Up @@ -667,5 +679,5 @@ Most of the image operations require GD. GD2 is greatly recommended

Version 1.x supports PHP 4, 5 and 7, but is not namespaced. Use it if you need support for PHP <5.3

Version 2.x supports PHP 5.3+ and PHP7.
Version 2.x supports PHP 5.3+ and PHP 7.

5 changes: 3 additions & 2 deletions external/class.upload/class.upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// | This script is free to use, don't abuse. |
// +------------------------------------------------------------------------+

namespace Verot\Upload;

if (!defined('IMG_WEBP')) define('IMG_WEBP', 32);

Expand All @@ -35,7 +36,7 @@
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @copyright Colin Verot
*/
class upload {
class Upload {


/**
Expand Down Expand Up @@ -2092,7 +2093,7 @@ function __construct($file, $lang = 'en_GB') {
*/
function upload($file, $lang = 'en_GB') {

$this->version = '02/08/2019';
$this->version = '03/08/2019';

$this->file_src_name = '';
$this->file_src_name_body = '';
Expand Down
4 changes: 2 additions & 2 deletions framework/modules/file/models/expFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ public static function fileUpload($_postName = null,
$resized = false;
$maxwidth = (int)($_max_width);
require_once(BASE . 'external/class.upload/class.upload.php');
$handle = new upload($_FILES[$_postName]);
$handle = new \Verot\Upload\Upload($_FILES[$_postName]);
$handle->file_new_name_body = pathinfo($_destFile, PATHINFO_FILENAME);
// $handle->file_new_name_ext = '';
$handle->dir_chmod = octdec(DIR_DEFAULT_MODE_STR + 0);
Expand Down Expand Up @@ -602,7 +602,7 @@ public static function fileXHRUpload($fileName = null,
$resized = false;
$maxwidth = (int)($_max_width);
require_once(BASE . 'external/class.upload/class.upload.php');
$handle = new upload('php:' . $fileName);
$handle = new \Verot\Upload\Upload('php:' . $fileName);
$handle->file_new_name_body = pathinfo($_destFile, PATHINFO_FILENAME);
// $handle->file_new_name_ext = '';
$handle->dir_chmod = octdec(DIR_DEFAULT_MODE_STR + 0);
Expand Down

0 comments on commit be5082c

Please sign in to comment.