nativephp/mobile-file
Composer 安装命令:
composer require nativephp/mobile-file
包简介
File operations plugin for NativePHP Mobile
README 文档
README
File operations (move, copy) for NativePHP Mobile applications.
Overview
The File API provides cross-platform file manipulation operations.
Installation
composer require nativephp/mobile-file
Usage
PHP (Livewire/Blade)
use Native\Mobile\Facades\File; // Move a file $result = File::move('/path/to/source.txt', '/path/to/destination.txt'); if ($result['success']) { echo 'File moved successfully!'; } // Copy a file $result = File::copy('/path/to/source.txt', '/path/to/copy.txt'); if ($result['success']) { echo 'File copied successfully!'; }
JavaScript (Vue/React/Inertia)
import { File } from '#nativephp'; // Move a file const result = await File.move('/path/to/source.txt', '/path/to/destination.txt'); if (result.success) { console.log('File moved successfully!'); } // Copy a file const result = await File.copy('/path/to/source.txt', '/path/to/copy.txt'); if (result.success) { console.log('File copied successfully!'); }
Methods
move(string $from, string $to): array
Moves a file from source to destination.
| Parameter | Type | Description |
|---|---|---|
from |
string | Source file path |
to |
string | Destination file path |
Returns:
success: bool- Whether the operation succeedederror: string- Error message if operation failed (optional)
copy(string $from, string $to): array
Copies a file from source to destination.
| Parameter | Type | Description |
|---|---|---|
from |
string | Source file path |
to |
string | Destination file path |
Returns:
success: bool- Whether the operation succeedederror: string- Error message if operation failed (optional)
Behavior
- Parent directories are created automatically if they don't exist
- Existing destination files are overwritten
- File integrity is verified after copy operations
- On Android, if rename fails (cross-filesystem), falls back to copy + delete
Examples
Move File to Permanent Storage
use Native\Mobile\Facades\File; $tempPath = '/var/mobile/Containers/Data/tmp/recording.m4a'; $permanentPath = storage_path('recordings/recording.m4a'); $result = File::move($tempPath, $permanentPath); if ($result['success']) { // File moved successfully }
Backup File Before Edit
use Native\Mobile\Facades\File; public function editFile($filePath) { // Create backup $backupPath = str_replace('.txt', '_backup.txt', $filePath); File::copy($filePath, $backupPath); // Proceed with editing... }
统计信息
- 总下载量: 3.47k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-03