I'm trying to copy a file from one location to another. I'm pretty sure the location is correct, but I'm still getting the error in the title.
Here's some code:
$oDirectory = new \RecursiveDirectoryIterator($extractFolder.'/res'); $oIterator = new \RecursiveIteratorIterator($oDirectory); foreach($oIterator as $oFile) { if ($oFile->getFilename() == 'icon.png') { $icons[filesize($oFile->getPath().'/icon.png')] = $oFile->getPath().'/icon.png'; } } asort($icons); print_r($icons); $icon_source = end($icons); echo $icon_source; $generated_icon_file = str_slug($packagename.$version).'.png'; Storage::copy($icon_source, $generated_icon_file);
The print_r
returns (which means the files exist):
Array ( [19950] => /var/www/apk.land/storage/extracted_apks/res/drawable-xxhdpi-v4/icon.png [31791] => /var/www/apk.land/storage/extracted_apks/res/drawable-xxxhdpi-v4/icon.png [6979] => /var/www/apk.land/storage/extracted_apks/res/drawable-hdpi-v4/icon.png [10954] => /var/www/apk.land/storage/extracted_apks/res/drawable-xhdpi-v4/icon.png )
The echo returns:
/var/www/apk.land/storage/extracted_apks/res/drawable-xxxhdpi-v4/icon.png
And the exact error is:
File not found at path: var/www/apk.land/storage/extracted_apks/res/drawable-xxxhdpi-v4/icon.png
P.S. PHP's copy
function works just great.
I can't find the problem here.
Any suggestions?
The reason you may experience a Path or File not found error is due to the incorrect set up of file-system paths (folders or directories) when dealing with documents or forms. Essentially the software may be trying to find or save a document to a folder and that path does not exist.
Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document.
Find the file or folder whose path you'd like to copy in File Explorer. Hold down Shift on your keyboard and right-click on it. In the context menu that pops up, select “Copy As Path.”
You said that the error is like this:
File not found at path: var/www/apk.land/storage/extracted_apks/res/drawable-xxxhdpi-v4/icon.png
Here error is saying it cannot find at var/www
that means it's looking for apk.land/var/www
whereas your file is located somewhere at /var/www
. A quick fix to this can be use file
protocol. Just use it like:
file:///var/www/storage/apk.land/storage/extracted_apks/res/drawable-xxxhdpi-v4/icon.png
Try with File::copy($file, $dest)
instead of Storage::copy($old, $new)
File::copy()
is the wrapper on PHP's copy()
function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With