2017-10-11 7 views
0

Je vois d'ici: rename a directory or a fileComment puis-je résoudre le fichier introuvable sur le chemin: ... lorsque renommer le fichier? (Laravel)

J'essaie comme ceci:

$destination_path = public_path() . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'products'. DIRECTORY_SEPARATOR . $product->id . DIRECTORY_SEPARATOR . $product->photo; 

$new_file_name = public_path() . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'products'. DIRECTORY_SEPARATOR . $product->id . DIRECTORY_SEPARATOR . $new_file_name; 

// dd($destination_path, $new_file_name); 

Storage::move($destination_path, $new_file_name); 

Il existe erreur:

[Ligue \ Flysystem \ FileNotFoundException] Fichier introuvable au chemin: C: /xampp/htdocs/myshop/public/img/products/147/Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png

Si je dd (chemin_destination de $, new_file_name de $), le résultat:

C: \ xampp \ htdocs \ myshop \ produits publics \ img \ \ 147 \ Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png

C: \ xampp \ htdocs \ myshop \ public \ produits img \ \ 147 \-chelsea.png 147 risque

J'essaie de vérifier Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png dans le dossier 147, le fichier existe

Pourquoi il existe une erreur?

Mise à jour:

j'avais trouver la solution. J'utilise un script php comme ceci:

rename($destination_path, $new_file_name);. Il fonctionne

+0

S'il n'y a personne pour vous aider? –

+0

s'il vous plaît vérifier dd (\ Storage :: exists ($ destination_path)); – honarkhah

+0

Utilisation de stockage C:/xampp/htdocs/myshop/stockage/application – honarkhah

Répondre

1

stockage Utilisation C:/xampp/htdocs/myshop/stockage/app
mais votre magasin de données sur le chemin du public

vous pouvez utiliser \ Storage :: existe ($ path);

$destination_path = public_path() . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'products'. DIRECTORY_SEPARATOR . $product->id . DIRECTORY_SEPARATOR . $product->photo; 

$new_file_name = public_path() . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'products'. DIRECTORY_SEPARATOR . $product->id . DIRECTORY_SEPARATOR . $new_file_name; 

// dd($destination_path, $new_file_name); 
if(\Storage::exists($destination_path)){ 
    Storage::move($destination_path, $new_file_name); 
} 
+0

J'ai essayé votre code . Ce n'est pas une erreur. Mais cela ne fonctionne pas pour renommer le nom de fichier –

+0

J'ai trouvé la solution. J'utilise un script PHP comme ceci: 'rename ($ destination_path, $ new_file_name);'. Cela fonctionne –

+0

stockage utiliser C:/xampp/htdocs/myshop/stockage/app mais vos fichiers sur le chemin public – honarkhah