Skip to content

Instantly share code, notes, and snippets.

@ElyDotDev
Last active February 14, 2016 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElyDotDev/131c2c665ded9768cb71 to your computer and use it in GitHub Desktop.
Save ElyDotDev/131c2c665ded9768cb71 to your computer and use it in GitHub Desktop.
SecureUPload – PHP secure file upload package Documentation: http://projects.allii.ir/project/secureupload/documentation/
<?php
$Config = new Alirdn\SecureUPload\Config\Config(
array(
'config_id' => 'config_value',
'config_another_id' => 0
)
);
echo $Config->get('config_id'); // echo config_value
<?php
$Config = new Alirdn\SecureUPload\Config\Config();
$Config->setArray(
array(
'config_id' => 'config_value',
'config_another_id' => 0
)
);
echo $Config->get('config_id'); // echo config_value
echo $Config->get('config_another_id'); // echo 0
echo $Config->get('config_non_exist_id'); // echo (empty string)
<?php
$Config = new Alirdn\SecureUPload\Config\Config();
$Config->setArray(
array(
'config_id' => 'config_value',
'config_another_id' => 0
)
);
$Config->printAll();
/*
Output:
<pre>
Array
(
[config_id] => config_value
[config_another_id] => 0
)
</pre>
*/
<?php
$Config = new Alirdn\SecureUPload\Config\Config;
$Config->set('config_id','config_value');
<?php
$Config = new Alirdn\SecureUPload\Config\Config();
$Config->setArray(
array(
'config_id' => 'config_value',
'config_another_id' => 0
)
);
<?php
$Config = new Alirdn\SecureUPload\Config\Config();
$Config
->setArray(
Array
(
[config_id] => config_value
[config_another_id] => 0
)
)
->set('final_config_id', 'final_value');
echo $Config->get('config_id'); // echo config_value
echo $Config->get('config_another_id'); // echo 0
echo $Config->get('config_non_exist_id'); // echo (empty string)
echo $Config->get('final_config_id'); // echo final_value
<?php
require_once "src/autoloader.php"
<html>
<form>
<!-- First !-->
<input type="file" name="images[]" />
<input type="file" name="images[]" />
<input type="file" name="images[]" />
<!-- Second !-->
<input type="file" name="images[]" multiple/>
<!-- For each of above example you should call $SecureUPload->uploadFiles('images'); !-->
</form>
</html>
<?php
$SecureUPloadConfig = new Alirdn\SecureUPload\Config\Config;
$SecureUPloadConfig->set('upload_folder', 'uploads' . DIRECTORY_SEPARATOR);
// Initialize Upload folder
$SecureUPload = new Alirdn\SecureUPload\SecureUPload($SecureUPloadConfig);
// Bypass Upload folder initialization
$SecureUPload = new Alirdn\SecureUPload\SecureUPload($SecureUPloadConfig, false);
<?php
$SecureUPloadConfig = new Alirdn\SecureUPload\Config\Config;
$SecureUPloadConfig->set('upload_folder', 'uploads' . DIRECTORY_SEPARATOR);
// Initialize Upload folder
$SecureUPload = new Alirdn\SecureUPload\SecureUPload($SecureUPloadConfig);
$Upload = $SecureUPload->getUpload('ca259cef4b42be49f7548e31aca10a29_png');
if($Upload->status == 1) {
// Upload is is correct and file exist
echo 'Uploaded file id is correct and file exist. Id: ' . $Upload->id . ' Path:' . $Upload->path;
} else {
// Given id is incorrect or file doesn't exist.
}
<?php
$SecureUPloadConfig = new Alirdn\SecureUPload\Config\Config;
$SecureUPloadConfig->set('upload_folder', 'uploads' . DIRECTORY_SEPARATOR);
// Initialize Upload folder
$SecureUPload = new Alirdn\SecureUPload\SecureUPload($SecureUPloadConfig);
$SecureUPload->getUploadAsFile('ca259cef4b42be49f7548e31aca10a29_png');
exit;
<?php
$SecureUPloadConfig = new Alirdn\SecureUPload\Config\Config;
$SecureUPloadConfig->set('upload_folder', 'uploads' . DIRECTORY_SEPARATOR);
// Initialize Upload folder
$SecureUPload = new Alirdn\SecureUPload\SecureUPload($SecureUPloadConfig);
$upload_removed = $SecureUPload->removeUpload('ca259cef4b42be49f7548e31aca10a29_png');
if($upload_removed) {
// Uploaded and stored file removed successfully.
} else {
// Even id is not correct, file dosent exist or removing from file system failed.
}
<?php
$SecureUPloadConfig = new Alirdn\SecureUPload\Config\Config;
$SecureUPloadConfig->set('upload_folder', 'uploads' . DIRECTORY_SEPARATOR);
// Initialize Upload folder
$SecureUPload = new Alirdn\SecureUPload\SecureUPload($SecureUPloadConfig);
$Upload = $SecureUPload->uploadFile('attachment');
/* Check that file uploaded or not. Then do corresponding action. */
if ( $Upload->status ) {
// File has been set in <input type="file" name="file"/>
if ( $Upload->status == 1 ) {
echo 'File uploaded successfully. Id: ' . $Upload->id;
} else {
echo 'File didn\'t uploaded. Error code: ' . $Upload->error;
}
} else {
// No file is selected in input field
}
<?php
$SecureUPloadConfig = new Alirdn\SecureUPload\Config\Config;
$SecureUPloadConfig->set('upload_folder', 'uploads' . DIRECTORY_SEPARATOR);
// Initialize Upload folder
$SecureUPload = new Alirdn\SecureUPload\SecureUPload($SecureUPloadConfig);
$uploads = $SecureUPload->uploadFiles('images');
/* Check that file uploaded or not. Then do corresponding action. */
if(!empty($uploads)) {
// Files for uploading have been selected
foreach($uploads as $Upload) {
if ( $Upload->status == 1 ) {
echo 'File uploaded successfully. Id: ' . $Upload->id;
} else {
echo 'File didn\'t uploaded. Error code: ' . $Upload->error;
}
}
} else {
// No files is selected in input fields
}
<?php
$SecureUPloadConfig = new Alirdn\SecureUPload\Config\Config;
$SecureUPloadConfig->set('upload_folder', 'uploads' . DIRECTORY_SEPARATOR);
// Initialize Upload folder
$SecureUPload = new Alirdn\SecureUPload\SecureUPload($SecureUPloadConfig);
$SecureUPload->getUploadAsFile('ca259cef4b42be49f7548e31aca10a29_png');
exit;
<?php
$SecureUPloadConfig = new Alirdn\SecureUPload\Config\Config;
$SecureUPloadConfig->set('upload_folder', 'uploads' . DIRECTORY_SEPARATOR);
// Initialize Upload folder
$SecureUPload = new Alirdn\SecureUPload\SecureUPload($SecureUPloadConfig);
$Upload = $SecureUPload->getUpload('ca259cef4b42be49f7548e31aca10a29_png');
if($Upload->status == 1) {
// Upload is is correct and file exist
// Echo $Upload->relative_url in image src etc...
} else {
// Given id is incorrect or file doesn't exist. So show an error or 404 not found
}
<?php
$SecureUPloadConfig = new Alirdn\SecureUPload\Config\Config;
$SecureUPloadConfig->set('upload_folder', 'uploads' . DIRECTORY_SEPARATOR);
// Initialize Upload folder
$SecureUPload = new Alirdn\SecureUPload\SecureUPload($SecureUPloadConfig);
$upload_removed = $SecureUPload->removeUpload('ca259cef4b42be49f7548e31aca10a29_png');
if($upload_removed) {
// Uploaded and stored file removed successfully.
} else {
// Even id is not correct, file dosent exist or removing from file system failed.
}
<?php
$SecureUPloadConfig = new Alirdn\SecureUPload\Config\Config;
$SecureUPloadConfig->set('upload_folder', 'uploads' . DIRECTORY_SEPARATOR);
// Initialize Upload folder
$SecureUPload = new Alirdn\SecureUPload\SecureUPload($SecureUPloadConfig);
$uploads = $SecureUPload->uploadFiles('images');
/* Check that file uploaded or not. Then do corresponding action. */
if(!empty($uploads)) {
// Files for uploading have been selected
foreach($uploads as $Upload) {
if ( $Upload->status == 1 ) {
// Save id to database
} else {
// Show corresponding error.
}
}
} else {
// If file is neccessary show error, if not, no action needed.
}
<?php
$SecureUPloadConfig = new Alirdn\SecureUPload\Config\Config;
$SecureUPloadConfig->set('upload_folder', 'uploads' . DIRECTORY_SEPARATOR);
// Initialize Upload folder
$SecureUPload = new Alirdn\SecureUPload\SecureUPload($SecureUPloadConfig);
$Upload = $SecureUPload->uploadFile('attachment');
/* Check that file uploaded or not. Then do corresponding action. */
if ( $Upload->status ) {
// File has been set in <input type="file" name="file"/>
if ( $Upload->status == 1 ) {
// Save id to database
} else {
// Show corresponding error.
}
} else {
// If file is neccessary show error, if not, no action needed.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment