We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7606
    • 39 Posts
    Hi everyone,

    My english is poor, sorry wink

    I’ve got a php file with php and html code, work perfect !

    When i cutted it into 2 parts for my modx-template (php-code for the snipped and html for the document) it doesn’t work anymore !


    The snippet i called [[azerty]]



    <?php

    if(isset($_FILES[’photo’]))
    // params
    unset($erreur);
    $extensions_ok = array(’png’, ’gif’, ’jpg’, ’jpeg’, ’doc’ );
    $taille_max = 10000000;
    $dest_dossier = ’frecu/’;

    // vérifications
    if( !in_array( substr(strrchr($_FILES[’photo’][’name’], ’.’), 1), $extensions_ok ) )
    {
    $erreur = ’Veuillez sélectionner un fichier de type png, gif ou jpg !’;
    }
    elseif( file_exists($_FILES[’photo’][’tmp_name’])
    and filesize($_FILES[’photo’][’tmp_name’]) > $taille_max)
    {
    $erreur = ’Votre fichier doit faire moins de 500Ko !’;
    }
    // copie du fichier
    if(!isset($erreur))
    {
    $dest_fichier = basename($_FILES[’photo’][’name’]);
    // formatage nom fichier
    // enlever les accents
    $dest_fichier = strtr($dest_fichier, ’ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ’, ’AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiii ioooooouuuuyy’);
    // remplacer les caracteres autres que lettres, chiffres et point par _
    $dest_fichier = preg_replace(’/([^.a-z0-1]+)/i’, ’_’, $dest_fichier);
    // copie du fichier
    move_uploaded_file($_FILES[’photo’][’tmp_name’], $dest_dossier . $dest_fichier);
    }
    }

    if(isset($erreur)){
    echo ’<p>’, $erreur ,’</p>’;

    ?>

    The second part for my .html file

    <!-- Formulaire -->
    <!-- Attention, ne de ne pas oublier le enctype="multipart/form-data" -->
    <form method="POST" enctype="multipart/form-data">
    <!-- Limiter la taille des fichiers à 500Ko -->
    <input type="hidden" name="MAX_FILE_SIZE" value="50000000" />
    <fieldset>
    <legend>Envoi de fichiers</legend>
    <!-- champs d’envoi de fichier, de type file -->
    <p><label for="photo">Photo :</label><input type="file" name="photo" /></p>
    <p><label for="photo_2">Photo 2 :</label><input type="file" name="photo_2" /></p>
    <!-- bouton d’envoi -->
    <p><input type="submit" name="envoi" value="Envoyer les fichiers" /></p>
    </legend>
    </fieldset>
    </form>

    When I copy/paste the 2 parts into 1 part and called it test.php, it is working ! but into 2 parts, doesn’t work.

    Second prob : when i call my snippet, i’ve got this on my screen "my modx page" (title) ? WHY ?

    Can you help me ?? pleaaaasee

    Thanks you so much !!!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      For one thing, your form has to have an action="[~[*id*]~]" attribute so that MODx knows to load up your form page (I presume that is where the snippet call is) again. Keep in mind that you’re actually using the index.php file for every page on your site, and that index.php file loads up the parser with the ID or alias of the actual document you want. So just leaving the form’s action to the default (the page it came from) will simply reload the index.php file with no indication which document needs to be loaded.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org