Available Disks
NativePHP provides the following pre-configured storage disks:| Disk Name | Environment Variable | Description |
|---|---|---|
user_home | NATIVEPHP_USER_HOME_PATH | User’s home directory |
app_data | NATIVEPHP_APP_DATA_PATH | Application data directory |
user_data | NATIVEPHP_USER_DATA_PATH | User-specific app data |
desktop | NATIVEPHP_DESKTOP_PATH | User’s Desktop folder |
documents | NATIVEPHP_DOCUMENTS_PATH | User’s Documents folder |
downloads | NATIVEPHP_DOWNLOADS_PATH | User’s Downloads folder |
music | NATIVEPHP_MUSIC_PATH | User’s Music folder |
pictures | NATIVEPHP_PICTURES_PATH | User’s Pictures folder |
videos | NATIVEPHP_VIDEOS_PATH | User’s Videos folder |
recent | NATIVEPHP_RECENT_PATH | Recently accessed files |
extras | NATIVEPHP_EXTRAS_PATH | Extra application files |
These disks are automatically configured when the corresponding environment variable is set. NativePHP’s runtime sets these variables based on the operating system.
Disk Configuration
Each disk is configured as a standard Laravel local filesystem disk:Configuration Options
- driver: Always
localfor system directories - root: The absolute path to the directory (from environment variable)
- throw: Set to
falseto returnfalseinstead of throwing exceptions - links: Set to
skipto skip symbolic links when scanning directories
Using Storage Disks
Use Laravel’s Storage facade to interact with these disks:Common Use Cases
Export to Desktop
Export files directly to the user’s Desktop:Import from Downloads
Process files from the Downloads folder:Save to Documents
Save user documents to the Documents folder:Backup to User Data
Store application data that should persist:File Path Helpers
Get absolute paths when you need them:Working with URLs
If you need to display files from these locations in your app:Best Practices
- User Folders: Always save user documents to appropriate system folders (Documents, Desktop, etc.)
- App Data: Use
app_dataoruser_datafor application-specific data - Permissions: Be mindful that users may have restricted permissions on some directories
- Error Handling: Always check if files exist before reading and handle exceptions
- Privacy: Only access directories that are necessary for your application’s functionality
Platform Differences
Be aware that directory locations vary by operating system:Platform-Specific Paths
Platform-Specific Paths
macOS
- Home:
/Users/username - Documents:
/Users/username/Documents - Desktop:
/Users/username/Desktop - App Data:
/Users/username/Library/Application Support/YourApp
- Home:
C:\Users\username - Documents:
C:\Users\username\Documents - Desktop:
C:\Users\username\Desktop - App Data:
C:\Users\username\AppData\Roaming\YourApp
- Home:
/home/username - Documents:
/home/username/Documents - Desktop:
/home/username/Desktop - App Data:
/home/username/.config/YourApp
Troubleshooting
Disk Not Available
If a disk is not available:- Check that the environment variable is set
- Verify the path exists and is accessible
- Check file permissions
- In development, some paths may not be set by the runtime
Permission Denied
If you get permission errors:- Verify your app has permission to access the directory
- Check that the user hasn’t restricted access
- On macOS, your app may need specific permissions granted by the user
- Use
app_dataoruser_datafor data your app owns
File Not Found
If files aren’t found:- Always use relative paths, not absolute paths
- Check file existence before reading
- Verify you’re using the correct disk
- Use
Storage::disk('name')->path('')to see the disk’s root path