Position actuelle: Accueil> Catégories de fonctions> sha1_file

sha1_file

Calculez la valeur de hachage SHA1 du fichier
Nom:sha1_file
Catégorie:Chaîne
Langage de programmation:php
Description en une ligne:Calculez le hachage SHA-1 du fichier.

Exemple

Exemple 1

Calculez le hachage SHA-1 du fichier texte "test.txt":

 <span class="token php language-php"><span class="token delimiter important"><? Php</span>
<span class="token variable">$ filename</span> <span class="token operator">=</span> <span class="token string double-quoted-string">"test.txt"</span> <span class="token punctuation">;</span>
<span class="token variable">$ sha1file</span> <span class="token operator">=</span> <span class="token function">sha1_file</span> <span class="token punctuation">(</span> <span class="token variable">$ nom de fichier</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token keyword">Echo</span> <span class="token variable">$ sha1file</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

Sortie du code ci-dessus:

 aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d

Exemple 2

Stockage du hachage SHA-1 de "test.txt" dans le fichier:

 <span class="token php language-php"><span class="token delimiter important"><? Php</span>
<span class="token variable">$ sha1file</span> <span class="token operator">=</span> <span class="token function">sha1_file</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"test.txt"</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token function">file_put_contents</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"sha1file.txt"</span> <span class="token punctuation">,</span> <span class="token variable">$ sha1file</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

Testez si "test.txt" a été modifié (c'est-à-dire si Sha-1 a été modifié):

 <span class="token php language-php"><span class="token delimiter important"><? Php</span>
<span class="token variable">$ sha1file</span> <span class="token operator">=</span> <span class="token function">file_get_contents</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"sha1file.txt"</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token function">sha1_file</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"test.txt"</span> <span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token variable">$ sha1file</span> <span class="token punctuation">)</span>
  <span class="token punctuation">{</span>
  <span class="token keyword">ECHO</span> <span class="token string double-quoted-string">"Le fichier est OK."</span> <span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token keyword">autre</span>
  <span class="token punctuation">{</span>
  <span class="token keyword">Echo</span> <span class="token string double-quoted-string">"Le fichier a été modifié".</span> <span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token delimiter important">?></span></span>

Sortie du code ci-dessus:

 Le fichier est ok.
Fonctions similaires
  • Chaîne formatée de sortie vprintf

    vprintf

    Chaîneformatéedesort
  • Convertissez le premier octet de la chaîne en une valeur entre 0-255 ord

    ord

    Convertissezlepremie
  • Convertissez tous les caractères applicables en entités HTML - Convertissez les caractères en caractères HTML Escape htmlentities

    htmlentities

    Convertisseztouslesc
  • Définissez le premier caractère de la chaîne en minuscules lcfirst

    lcfirst

    Définissezlepremierc
  • Insérez la balise HTML Newline avant toutes les nouvelles lignes d'une chaîne nl2br

    nl2br

    InsérezlabaliseHTMLN
  • Obtenez la longueur de la sous-chaîne de démarrage qui ne correspond pas au masque strcspn

    strcspn

    Obtenezlalongueurdel
  • Chaîne de comparaison de sécurité binaire (comparez la longueur spécifiée de la position de décalage) substr_compare

    substr_compare

    Chaînedecomparaisond
  • Trouvez la première occurrence de sous-chaînes dans les cordes strpos

    strpos

    Trouvezlapremièreocc
Articles populaires