Advanced customization options for power users and specific use cases.
You can customize where files are stored beyond the default upload directory.
The storage path should be:
mkdir -p /path/to/custom/storage
chown www-data:www-data /path/to/custom/storage
chmod 755 /path/to/custom/storage
You can use absolute paths for storage outside the YOURLS directory:
/var/www/files/uploads/
/home/user/public_html/files/
/mnt/storage/yourls-uploads/
Relative paths are based on YOURLS installation directory:
user/uploads/
../shared-files/
uploads/documents/
Configure different locations for different purposes:
/uploads/images/ - For images only
/uploads/documents/ - For PDFs and documents
/uploads/archives/ - For ZIP files
/uploads/temporary/ - For files with short expiration
Configure rate limits to prevent abuse and control resource usage.
Add to your YOURLS user/config.php:
// Uploads per hour for frontend users
define('UPLOAD_RATE_LIMIT', 5);
// Time window in seconds (3600 = 1 hour)
define('UPLOAD_RATE_WINDOW', 3600);
// Uploads per hour for authenticated admin users
define('UPLOAD_ADMIN_RATE_LIMIT', 100);
When limit is exceeded, users receive:
To whitelist specific IPs from rate limiting:
define('UPLOAD_RATE_LIMIT_WHITELIST', [
'192.168.1.100',
'10.0.0.50',
]);
View rate limit statistics:
The plugin validates files on multiple levels to ensure security and compliance.
Define allowed MIME types in user/config.php:
define('UPLOAD_ALLOWED_MIMES', [
'image/jpeg',
'image/png',
'image/gif',
'application/pdf',
'application/zip',
'text/plain',
]);
Add custom validation logic:
// In user/config.php or custom plugin
yourls_add_filter('upload_validate_file', 'my_custom_validation');
function my_custom_validation($file) {
// Custom validation logic
if ($file['size'] > 5000000 && $file['type'] == 'image/jpeg') {
return ['error' => 'JPEG images must be under 5MB'];
}
return $file;
}
Enable deep content scanning for enhanced security:
define('UPLOAD_DEEP_SCAN', true); // Enables thorough content analysis
define('UPLOAD_SCAN_LEVEL', 'strict'); // Options: 'basic', 'moderate', 'strict'
Block files containing specific patterns:
define('UPLOAD_BLOCKED_PATTERNS', [
'<?php',
'<script>',
'eval(',
'base64_decode(',
]);
Optimize the plugin for CyberPanel with OpenLiteSpeed or LiteSpeed Enterprise.
Enable caching for download URLs:
# Add to .htaccess in uploads directory
<IfModule LiteSpeed>
CacheLookup on
RewriteRule .* - [E=Cache-Control:max-age=86400]
</IfModule>
For OpenLiteSpeed on CyberPanel:
Options -Indexes
<IfModule mod_mime.c>
AddType image/jpeg .jpg .jpeg
AddType image/png .png
AddType image/gif .gif
AddType application/pdf .pdf
</IfModule>
systemctl restart lsws
For LiteSpeed Enterprise:
Apply changes to .htaccess
Restart LiteSpeed:
systemctl restart lsws
curl -I https://yourls.example.com/uploads/test.jpg
The plugin respects CyberPanel’s file ownership rules:
yourls_user:nobodyyourls_user:yourls_userExtend the plugin with programmatic access.
The plugin provides REST API endpoints:
POST /api/upload - Upload a file
GET /api/files - List uploaded files
GET /api/files/{id} - Get file details
DELETE /api/files/{id} - Delete a file
PUT /api/files/{id} - Update file metadata
API requests require YOURLS authentication:
curl -X POST https://yourls.example.com/api/upload \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@document.pdf"
All API responses use JSON:
{
"status": "success",
"data": {
"file_id": "abc123",
"short_url": "https://yourls.example.com/abc123",
"filename": "document.pdf"
}
}
Make the plugin work seamlessly with custom YOURLS themes.
Override default styles in your theme:
/* In your theme's style.css */
.upload-container {
background: #your-color;
border: 1px solid #your-border;
}
.upload-button {
background: #your-button-color;
}
Override plugin templates by creating files in your theme:
your-theme/
└── upload-and-shorten/
├── upload-form.php
├── file-list.php
└── settings-page.php
Use available hooks in your theme:
// Add custom content before upload form
yourls_add_action('upload_before_form', 'my_custom_content');
function my_custom_content() {
echo '<div class="custom-notice">Upload your files here!</div>';
}
Optimize plugin performance for large-scale deployments.
Add indexes for better query performance:
ALTER TABLE yourls_upload_files ADD INDEX idx_upload_date (upload_date);
ALTER TABLE yourls_upload_files ADD INDEX idx_expiration (expiration_date);
ALTER TABLE yourls_upload_files ADD INDEX idx_user (user_id);
Enable object caching for frequently accessed data:
define('UPLOAD_ENABLE_CACHE', true);
define('UPLOAD_CACHE_TTL', 3600); // 1 hour
For large files or high traffic:
Regularly clean up expired rate limit data:
# Add to cron
0 0 * * * /usr/bin/php /path/to/yourls/user/plugins/YOURLS-Upload-and-Shorten-Advanced/cleanup-rate-limits.php
Additional security measures for production environments.
Add to uploads directory .htaccess:
Options -Indexes
Restrict uploads to specific IPs:
define('UPLOAD_ALLOWED_IPS', [
'192.168.1.0/24',
'10.0.0.0/8',
]);
Track all upload activities:
define('UPLOAD_AUDIT_LOG', true);
define('UPLOAD_AUDIT_FILE', '/var/log/yourls/uploads.log');
Integrate with ClamAV for virus scanning:
define('UPLOAD_VIRUS_SCAN', true);
define('UPLOAD_CLAMAV_SOCKET', '/var/run/clamav/clamd.ctl');