Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File not found at path when trying to copy

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?

like image 471
Alex Avatar asked Aug 19 '15 18:08

Alex


People also ask

Why is my file path not working?

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.

How do I copy the file path to a file?

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.

How do I copy the filename and path?

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.”


2 Answers

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 
like image 156
Aditya Giri Avatar answered Oct 13 '22 11:10

Aditya Giri


Try with File::copy($file, $dest) instead of Storage::copy($old, $new)
File::copy() is the wrapper on PHP's copy() function

like image 45
Halayem Anis Avatar answered Oct 13 '22 12:10

Halayem Anis