PHP - "Class not found" error when the program try to find class at the project -
i downloaded github component simplifies file validation , uploading (https://github.com/brandonsavage/upload).
i put src folder @ www folder (i working wamp).
i installed composer.json givven @ github progaramץ
i created index.html file 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 up.php copied readme (at github project) that:
<?php $storage = new \upload\storage\filesystem(__dir__."/".$sugar_config['upload_dir']); $file = new \upload\file('foo', $storage); // optionally can rename 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 of type "image/png" new \upload\validation\mimetype('image/png'), //you can add multi mimetype validation //new \upload\validation\mimetype(array('image/png', 'image/gif')) // ensure file no larger 5m (use "b", "k", m", or "g") new \upload\validation\size('5m') )); // access data file has been uploaded $data = array( 'name' => $file->getnamewithextension(), 'extension' => $file->getextension(), 'mime' => $file->getmimetype(), 'size' => $file->getsize(), 'md5' => $file->getmd5(), 'dimensions' => $file->getdimensions() ); // try upload file try { // success! $file->upload(); } catch (\exception $e) { // fail! $errors = $file->geterrors(); }
after clicking upload file buttom @ index browser directing me up.php file error:
i tried fix with:
- adding
namespace upload;
other pages have. - changing path @ line -
$storage = new \upload\storage\filesystem(__dir__."/".$sugar_config['upload_dir']);
nothing works.
===== update - after adding require dirname(__dir__) . '\upload\vendor\autoload.php';
still 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
it not work, if don't use composer , composer's autoloader, package has it's own class autoloader, try include autoloader , register @ top of script:
include 'src/upload/autoloader.php' autoloader::register();
Comments
Post a Comment