IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Upload de fichier "chunké" ?


Sujet :

Langage PHP

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 14
    Points : 10
    Points
    10
    Par défaut Upload de fichier "chunké" ?
    Bonjour,
    je suis en archi client/serveur
    et mon client java envoi un fichier chunké a mon serveur php... comment je peux faire pour recuperer le fichier entier ?

    Lorsque je ne passais pas par une fonction pour chunker le fichier, j'avais le code suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    <?php
    $folderPath = "./upload/"
    if( !move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $folderPath . $_FILES['uploadedfile']['name']) )
    {
       exit("  Impossible to copy.");
    }
    exit("  Oki !");
    ?>
    Mais ca ne marche plus depuis que je suis obligé de chunker le fichier (fichier mp3 de 10Mo) ... :S

  2. #2
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 228
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 228
    Points : 8 487
    Points
    8 487
    Billets dans le blog
    17
    Par défaut
    et mon client java envoi un fichier chunké a mon serveur php... comment je peux faire pour recuperer le fichier entier ?
    Tu "concatènes" chq bout de fichier uploadé au précédent de manière à reconstituer le mp3 complet.

    http://fr.php.net/file-put-contents
    http://fr.php.net/file-get-contents

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 14
    Points : 10
    Points
    10
    Par défaut
    Merci,
    mais avec mon code ca donnerait quoi ?
    J'ai du mal a utiliser ces fonctions sur mon cas !

  4. #4
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 228
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 228
    Points : 8 487
    Points
    8 487
    Billets dans le blog
    17
    Par défaut
    Je ne peux pas te répondre car je ne sais pas comment tu gères tes uploads actuellement.

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 14
    Points : 10
    Points
    10
    Par défaut
    o_0
    Bah j'ai mis mon code plus haut !

    Tu veux le code coté client ? Ca apporte quoi de plus ?

  6. #6
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 228
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 228
    Points : 8 487
    Points
    8 487
    Billets dans le blog
    17
    Par défaut
    Citation Envoyé par SLy17 Voir le message
    o_0
    Bah j'ai mis mon code plus haut !
    Tu disais :

    Lorsque je ne passais pas par une fonction pour chunker le fichier, j'avais le code suivant :
    Ce qui laissait penser que tu n'utilisais plus ce script.

    Tu veux le code coté client ?
    Non.
    Par contre savoir comment tu gères la chose côte client aidera. Donne un exemple concret.

  7. #7
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 14
    Points : 10
    Points
    10
    Par défaut
    Oki, alors en fait coté serveur j'ai essayé autre chose que le code ci dessus mais rien qui marche, donc pour le moment j'utilise ce code !

    Coté client j'utilise une HttpUrlConnection (en fait c'est du android, donc du java). Ca donne ca :

    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
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
     
    String fullFilePath = "/sdcard/" + filename;
     
    File targetFile = new File(fullFilePath);
    if (!targetFile.exists()){
    	Log.e("MediaPlayer","The file doesn't exist");
    	return;
    }
     
    HttpURLConnection conn = null;
    DataOutputStream dos = null;
    DataInputStream inStream = null;
     
    String lineEnd = "\r\n";
    String twoHyphens = "--";
    String boundary = "*****";
     
    int bytesRead, bytesAvailable, bufferSize;
    byte[] buffer;
    int maxBufferSize = 1 * 1024 * 1024;
    String urlString = "http://mon_adresse/Upload/upload.php";
     
    try
    {
    	//------------------ CLIENT REQUEST
     
    	//mHandler.post(updateProgressBar);
     
    	  FileInputStream fileInputStream = new FileInputStream(new File(fullFilePath));
     
    	   URL url = new URL(urlString);
    	   conn = (HttpURLConnection) url.openConnection();
    	   conn.setRequestMethod("POST");
    	   conn.setRequestProperty("Connection", "Keep-Alive");
    	   conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
     
    	   conn.setDoInput(true);
    	   conn.setDoOutput(true);
    	   conn.setUseCaches(false);
     
    	   conn.setChunkedStreamingMode(maxBufferSize);
     
    	   // Use a post method.
    	   dos = new DataOutputStream(conn.getOutputStream());
    	   dos.writeBytes(twoHyphens + boundary + lineEnd);
    	   dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\"; filename=\"" + fullFilePath +"\"" + lineEnd);
    	   dos.writeBytes(lineEnd);
     
    	   // create a buffer of maximum size
    	   bytesAvailable = fileInputStream.available();
    	   bufferSize = 1024;//Math.min(bytesAvailable, maxBufferSize);
    	   buffer = new byte[bufferSize];
     
    	   // read file and write it into form...
    	   bytesRead = fileInputStream.read(buffer, 0, bufferSize);
    	   while (bytesRead > 0)
    	   {
    			//mHandler.post(updateProgressBar); 
     
    		   dos.write(buffer, 0, bufferSize);
    			//bytesAvailable = fileInputStream.available();
    			//bufferSize = Math.min(bytesAvailable, maxBufferSize);
    			bytesRead = fileInputStream.read(buffer, 0, bufferSize);
    	   }
     
    	   // send multipart form data necesssary after file data...
    	   dos.writeBytes(lineEnd);
    	   dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
     
    	   // close streams
    	   buffer = null;
    	   dos.flush();
    	   dos.close(); 
    	   fileInputStream.close();
    }
    catch (MalformedURLException ex)
    {
    	Log.e("MediaPlayer", "error: " + ex.getMessage(), ex);
    }
    catch (IOException ioe)
    {
    	Log.e("MediaPlayer", "error: " + ioe.getMessage(), ioe);
    }
     
    //------------------ read the SERVER RESPONSE
    try {
    	inStream = new DataInputStream (conn.getInputStream());
    	String str;
     
    	while (( str = inStream.readLine()) != null)
    	{
    		 Log.e("MediaPlayer","Server Response"+str);
    	}
    	inStream.close();
     
    }
    catch (IOException ioex){
       Log.e("MediaPlayer", "error: " + ioex.getMessage(), ioex);
    }
    et je passe en mode "chunk" avec la ligne conn.setChunkedStreamingMode(maxBufferSize); j'ai essayé plusieurs valeurs pour cette fonction mais pas de changement. Coté client ca parait passer, mais du coup coté serveur ma variable $_FILES parait etre vide ! (D'ailleurs elle l'est puisque je viens de faire un print_r($_FILES); et ca me retourne un Array vide !)

  8. #8
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 228
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 228
    Points : 8 487
    Points
    8 487
    Billets dans le blog
    17
    Par défaut
    Coté client ca parait passer, mais du coup coté serveur ma variable $_FILE parait etre vide !
    Si $_FILES est vide alors il faut revoir le code du client.

    Sinon pour quelle raison dois-tu couper ton fichier ? On peut peut-être jouer sur la config de PHP.

  9. #9
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 14
    Points : 10
    Points
    10
    Par défaut
    J'avais rectifié pour le S

    En fait j'ai regardé la variable always_populate_raw_post_data de la config du serveur et elle vaut 0 (donc false)... il me semble avoir lu qu'il fallait que cette variable soit a true pour permettre le chunk... quelqu'un pour confirmer ?

    Question config sinon l'upload est limité a 24Mo et moi je bloque a 4 ! Et quand je fais un formulaire HTML pour tester cette limite de 24Mo, mes fichiers passent bien !

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo