I downloaded from github component that simplifies file validation and uploading (https://github.com/brandonsavage/Upload).
I put all the src folder at www folder (I working with WAMP).
I also installed the composer.json that givven at the github progaramץ
I created index.html file with this code:
<!DOCTYPE html>
<html>
<body>
<form action="up.php" method="POST" enctype="multipart/form-data">
<input type="file" name="foo" value=""/>
<input type="submit" value="Upload File"/>
</form>
</body>
</html>
The action direct to up.php that i copied from the Readme (at the github project) like that:
<?php
$storage = new \Upload\Storage\FileSystem(__DIR__."/".$sugar_config['upload_dir']);
$file = new \Upload\File('foo', $storage);
// Optionally you can rename the file on upload
$new_filename = uniqid();
$file->setName($new_filename);
// Validate file upload
// MimeType List => http://www.iana.org/assignments/media-types/media-types.xhtml
$file->addValidations(array(
// Ensure file is of type "image/png"
new \Upload\Validation\Mimetype('image/png'),
//You can also add multi mimetype validation
//new \Upload\Validation\Mimetype(array('image/png', 'image/gif'))
// Ensure file is no larger than 5M (use "B", "K", M", or "G")
new \Upload\Validation\Size('5M')
));
// Access data about the file that has been uploaded
$data = array(
'name' => $file->getNameWithExtension(),
'extension' => $file->getExtension(),
'mime' => $file->getMimetype(),
'size' => $file->getSize(),
'md5' => $file->getMd5(),
'dimensions' => $file->getDimensions()
);
// Try to upload file
try {
// Success!
$file->upload();
} catch (\Exception $e) {
// Fail!
$errors = $file->getErrors();
}
After clicking the Upload file buttom at the index the browser directing me to the up.php file but with this error:
I tried to fix it with:
- Adding
namespace Upload;like the other pages have. - Changing the path at this line -
$storage = new \Upload\Storage\FileSystem(__DIR__."/".$sugar_config['upload_dir']);
Nothing works.
=====
Update - after adding the require dirname(__DIR__) . '\Upload\vendor\autoload.php'; i still get the same error -
( ! ) Fatal error: Class 'Upload\Storage\FileSystem' not found in C:\wamp\www\Upload\up.php on line 7
Time Memory Function Location
1 0.0084 250616 {main}( ) ..\up.php:0