Fonction File Uploads Php
Résolu
aureliendu917
Messages postés
267
Date d'inscription
Statut
Membre
Dernière intervention
-
aureliendu917 Messages postés 267 Date d'inscription Statut Membre Dernière intervention -
aureliendu917 Messages postés 267 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
voila j'ai un probleme je voudrai que quand un personne uploads une images je voudrai que que le fichiers se renommer si elle existe deja est ce que vous pouvez m'aidez svp voici mon code
Merci a vous
voila j'ai un probleme je voudrai que quand un personne uploads une images je voudrai que que le fichiers se renommer si elle existe deja est ce que vous pouvez m'aidez svp voici mon code
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
Merci a vous
Configuration: Windows Vista Firefox 3.0.11
26 réponses
- 1
- 2
Suivant
-
fais afficher le nom généré pour le fichier et vérifies si il existe déjà sur ton disque :
<?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); while(file_exists($target_path)) $target_path = $target_path.rand(0, 9); var_dump($target_path); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> -
salut,
de tête, je penserais à :<?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); while(file_exists($target_path)) $target_path = $target_path.rand(0, 9); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?>
-
dsl sa marche pas !!!
-
merci sa marche mai le problème sait que le chiffre se mai après l'extension et sa donne ça images.png2
-
ah ben oui, qu'est-ce que je suis c** !
désolé, je réfléchis pas j'applique du code bêtement…<?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); while(file_exists($target_path)) { $name = pathinfo($target_path, 'filename'); $ext = pathinfo($target_path, 'extension'); $target_path = $name.rand(0, 9).$ext; } if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?>
-
-
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question -
il y a encore un probleme lol :
Warning: pathinfo() expects parameter 2 to be long, string given in C:\wamp\www\ok.php on line 7 Warning: pathinfo() expects parameter 2 to be long, string given in C:\wamp\www\ok.php on line 8 The file bouton.png has been uploaded
-
ce coup-ci je plaide non coupable !!!
j'ai pris les arguments dans le manuel PHP (version locale en CHM), "c'est pas d'ma faute m'sieur l'agent !".
-:oD
while(file_exists($target_path)) { $name = pathinfo($target_path, PATHINFO_FILENAME); $ext = pathinfo($target_path, PATHINFO_EXTENSION); $target_path = $name.rand(0, 9).$ext; } -
j'ai teste en ligne et sa m'affiche la même erreur !!
-
grrrr !
le point bon sang !
bon ce coup -ci j'ai essayé, ça fonctionne !while(file_exists($target_path)) { $name = pathinfo($target_path, PATHINFO_FILENAME); $ext = pathinfo($target_path, PATHINFO_EXTENSION); $target_path = $name.rand(0, 9).'.'.$ext; var_dump($target_path); } -
merci mais je sais je suis casse noisette mait il y a encore un probleme cet fois le fichier me vos pas dans le fichier "uploads"
-
que t'affiche le "var_dump($target_path);" ?
ce n'est pas une adresse correcte ?
as-tu essayé sans le "var_dump($target_path);", ça peut être lui qui empêche la suite du code de s'exécuter correctement.
-
j'ai enlever le code :
var_dump($target_path);
mait la sa copie plus du tous -
et quand il y avait le "var_dump($target_path);", il affichait quoi comme erreur ?
-
quand je l'enlève ça renommer plus si il excite deja
-
il t'affiche quoi comme nom de fichier ?
-
sa m'affiche le mon d'origine de l'images par exemple "images.png"
-
while(file_exists($target_path)) { $name = pathinfo($target_path, PATHINFO_FILENAME); $ext = pathinfo($target_path, PATHINFO_EXTENSION); $target_path = $name.rand(0, 9).'.'.$ext; var_dump($target_path); }
ça ?
je viens de le tester avec un "index.php" existant et il me renvoie "index1.php"…
-
sa copie et ça renommer bien mai il envoie pas le fichier dans le dossier "uploads" !
-
ah ben tu vois que tu peux être clair des fois !
-:oD
je te dirais bien de faire un petit "var_dump($_FILES);" pour savoir ce que le serveur reçoit comme fichier…
-
sa renvoie ça :
array(1) { ["uploadedfile"]=> array(5) { ["name"]=> string(13) "bannieres.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(23) "C:\wamp\tmp\php9504.tmp" ["error"]=> int(0) ["size"]=> int(70830) } } The file bannieres.png has been uploaded -
et tu as regardé ailleurs que dans "uploads" ?
genre un dossier ou deux au dessus ?
parce que le fichier existe bien et il le déplace bien des temporaires vars ailleurs, reste à trouver le ailleurs…
- 1
- 2
Suivant