Bonjour,
j'ai un problème sur un upload de fichier et même si le chat, on n'a pas pu le résoudre. Je passe donc par le forum.
Voici mon formulaire HTML (index.php) :
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 Tentative de upload d'un fichier <form enctype='multipart/form-data' method="post" action="upload.php"> <input type="file" name="fichier"/> <input type="submit" name="submit" value="Envoyer"/> </form>
Voila mon traitement (upload.php):
Et voici le résultat :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 <?php print_r($_POST); print_r($_FILES); // Declare variables // Get the basic file information $userfile = $_FILES['fichier']['name']; $file_size = $_FILES['fichier']['size']; $file_temp = $_FILES['fichier']['tmp_name']; $file_err = $_FILES['fichier']['error']; $path = 'uploads/'; // Create a new file name // This is so if other files on the server have the same name, it will be renamed $randomizer = rand(0000, 9999); $file_name = $randomizer.$userfile; // Get the file type // Using $_FILES to get the file type is sometimes inaccurate, so we are going // to get the extension ourselves from the name of the file // This also eliminates having to worry about the MIME type $file_type = $userfile; $file_type_length = strlen($file_type) - 3; $file_type = substr($file_type, $file_type_length); if(!empty($userfile)) { echo '<div style="font-weight: bold; padding: 6px;">File Uploaded Information</div> <ul> <li>Original File Name: ' .$userfile. '</li> <li>New File Name: ' .$file_name. '</li> <li>File Type: ' .$file_type.'</li> <li>File Size: ' .$file_size. '</li> <li>File Temporary Name: ' .$file_temp. '</li> <li>Fille Error: ' . $file_err. '</li> </ul>'; // limit the size of the file to 200KB if($file_size > 25600) { echo 'FILE SIZE TO LARGE<BR />'; exit(); } // Set allowed file types // Set case of all letters to lower case $file_type = strtolower($file_type); $files = array(); $files[] = 'jpeg'; $files[] = 'jpg'; $files[] = 'gif'; $files[] = 'png'; $files[] = 'txt'; // Search the array for the allowed file type $key = array_search($file_type, $files); if($key) { echo '<b>File allowed!</b><br />'; } else { echo '<b>ILLEGAL FILE TYPE</b><br />'; exit(); } // Check for errors and upload the file $error_count = count($file_error); if($error_count > 0) { for($i = 0; $i <= $error_count; ++$i) { echo $_FILES['userfile']['error'][$i]; } } else { if(move_uploaded_file($file_temp, 'images/' .$file_name.'')) { echo '<h3>Upload Successful!</h3>'; } else { echo '<h3>ERROR</h3>'; } } } else { echo '<h3>No file has been selected.</h3>'; } ?>
Code x : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 Array ( [fichier] => bla.txt [submit] => Envoyer ) Array ( ) Notice: Undefined index: fichier in C:\Documents and Settings\emmay57n\Bureau\testWeb\testFichier\upload.php on line 7 Notice: Undefined index: fichier in C:\Documents and Settings\emmay57n\Bureau\testWeb\testFichier\upload.php on line 8 Notice: Undefined index: fichier in C:\Documents and Settings\emmay57n\Bureau\testWeb\testFichier\upload.php on line 9 Notice: Undefined index: fichier in C:\Documents and Settings\emmay57n\Bureau\testWeb\testFichier\upload.php on line 10 No file has been selected.
En gros il n'upload pas le fichier...
Avez vous des idées ?
Merci par avance.
Cordialement,
Tid.
Partager