summaryrefslogtreecommitdiff
path: root/ext/standard/tests/strings/md5_file.phpt
blob: 45009669f4ac4f75038c23163d7c230fe878de30 (plain)
ofshex dumpascii
0000 2d 2d 54 45 53 54 2d 2d 0a 54 65 73 74 20 6d 64 35 5f 66 69 6c 65 28 29 20 66 75 6e 63 74 69 6f --TEST--.Test.md5_file().functio
0020 6e 20 77 69 74 68 20 41 53 43 49 49 20 6f 75 74 70 75 74 20 61 6e 64 20 72 61 77 20 62 69 6e 61 n.with.ASCII.output.and.raw.bina
0040 72 79 20 6f 75 74 70 75 74 0a 2d 2d 46 49 4c 45 2d 2d 0a 3c 3f 70 68 70 0a 0a 2f 2a 20 50 72 6f ry.output.--FILE--.<?php../*.Pro
0060 74 6f 74 79 70 65 3a 20 73 74 72 69 6e 67 20 6d 64 35 5f 66 69 6c 65 28 20 73 74 72 69 6e 67 20 totype:.string.md5_file(.string.
0080 66 69 6c 65 6e 61 6d 65 5b 2c 20 62 6f 6f 6c 20 72 61 77 5f 6f 75 74 70 75 74 5d 20 29 0a 20 2a filename[,.bool.raw_output].)..*
00a0 20 44 65 73 63 72 69 70 74 69 6f 6e 3a 20 43 61 6c 63 75 6c 61 74 65 20 74 68 65 20 4d 44 35 20 .Description:.Calculate.the.MD5.
00c0 68 61 73 68 20 6f 66 20 61 20 67 69 76 65 6e 20 66 69 6c 65 0a 20 2a 2f 0a 0a 2f 2a 20 43 72 65 hash.of.a.given.file..*/../*.Cre
00e0 61 74 69 6e 67 20 61 6e 20 65 6d 70 74 79 20 66 69 6c 65 20 2a 2f 0a 69 66 20 28 28 24 68 61 6e ating.an.empty.file.*/.if.(($han
0100 64 6c 65 20 3d 20 66 6f 70 65 6e 28 20 22 45 6d 70 74 79 46 69 6c 65 4d 44 35 2e 74 78 74 22 2c dle.=.fopen(."EmptyFileMD5.txt",
0120 20 22 77 2b 22 29 29 20 3d 3d 20 46 41 4c 53 45 29 0a 72 65 74 75 72 6e 20 66 61 6c 73 65 3b 0a ."w+")).==.FALSE).return.false;.
0140 0a 2f 2a 20 43 72 65 61 74 69 6e 67 20 61 20 64 61 74 61 20 66 69 6c 65 20 2a 2f 0a 69 66 20 28 ./*.Creating.a.data.file.*/.if.(
0160 28 24 68 61 6e 64 6c 65 32 20 3d 20 66 6f 70 65 6e 28 20 22 44 61 74 61 46 69 6c 65 4d 44 35 2e ($handle2.=.fopen(."DataFileMD5.
0180 74 78 74 22 2c 20 22 77 2b 22 29 29 20 3d 3d 20 46 41 4c 53 45 29 0a 72 65 74 75 72 6e 20 66 61 txt",."w+")).==.FALSE).return.fa
01a0 6c 73 65 3b 0a 0a 2f 2a 20 57 72 69 74 69 6e 67 20 69 6e 74 6f 20 66 69 6c 65 20 2a 2f 0a 24 66 lse;../*.Writing.into.file.*/.$f
01c0 69 6c 65 6e 61 6d 65 20 3d 20 22 44 61 74 61 46 69 6c 65 4d 44 35 2e 74 78 74 22 3b 0a 24 63 6f ilename.=."DataFileMD5.txt";.$co
01e0 6e 74 65 6e 74 20 3d 20 22 41 64 64 20 74 68 69 73 20 74 6f 20 74 68 65 20 66 69 6c 65 5c 6e 22 ntent.=."Add.this.to.the.file\n"
0200 3b 0a 69 66 20 28 69 73 5f 77 72 69 74 61 62 6c 65 28 24 66 69 6c 65 6e 61 6d 65 29 29 20 7b 0a ;.if.(is_writable($filename)).{.
0220 20 20 69 66 20 28 66 77 72 69 74 65 28 24 68 61 6e 64 6c 65 32 2c 20 24 63 6f 6e 74 65 6e 74 29 ..if.(fwrite($handle2,.$content)
0240 20 3d 3d 3d 20 46 41 4c 53 45 29 20 7b 0a 20 20 20 20 65 63 68 6f 20 22 43 61 6e 6e 6f 74 20 77 .===.FALSE).{.....echo."Cannot.w
0260 72 69 74 65 20 74 6f 20 66 69 6c 65 20 28 24 66 69 6c 65 6e 61 6d 65 29 22 3b 0a 20 20 20 20 65 rite.to.file.($filename)";.....e
0280 78 69 74 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2f 20 63 6c 6f 73 65 20 74 68 65 20 66 69 6c 65 73 0a 66 xit;...}.}..//.close.the.files.f
02a0 63 6c 6f 73 65 28 24 68 61 6e 64 6c 65 29 3b 0a 66 63 6c 6f 73 65 28 24 68 61 6e 64 6c 65 32 29 close($handle);.fclose($handle2)
02c0 3b 0a 0a 2f 2a 20 54 65 73 74 69 6e 67 20 65 72 72 6f 72 20 63 6f 6e 64 69 74 69 6f 6e 73 20 2a ;../*.Testing.error.conditions.*
02e0 2f 0a 65 63 68 6f 20 22 5c 6e 2a 2a 2a 20 54 65 73 74 69 6e 67 20 66 6f 72 20 65 72 72 6f 72 20 /.echo."\n***.Testing.for.error.
0300 63 6f 6e 64 69 74 69 6f 6e 73 20 2a 2a 2a 5c 6e 22 3b 0a 0a 2f 2a 20 4e 6f 20 66 69 6c 65 6e 61 conditions.***\n";../*.No.filena
0320 6d 65 20 2a 2f 0a 76 61 72 5f 64 75 6d 70 28 20 6d 64 35 5f 66 69 6c 65 28 22 22 29 20 29 3b 0a me.*/.var_dump(.md5_file("").);.
0340 0a 2f 2a 20 69 6e 76 61 6c 69 64 20 66 69 6c 65 6e 61 6d 65 20 2a 2f 0a 76 61 72 5f 64 75 6d 70 ./*.invalid.filename.*/.var_dump
0360 28 20 6d 64 35 5f 66 69 6c 65 28 22 61 5a 72 71 31 36 75 22 29 20 29 3b 0a 0a 2f 2a 20 53 63 61 (.md5_file("aZrq16u").);../*.Sca
0380 6c 61 72 20 76 61 6c 75 65 20 61 73 20 66 69 6c 65 6e 61 6d 65 20 20 2a 2f 0a 76 61 72 5f 64 75 lar.value.as.filename..*/.var_du
03a0 6d 70 28 20 6d 64 35 5f 66 69 6c 65 28 31 32 29 20 29 3b 0a 0a 2f 2a 20 4e 55 4c 4c 20 61 73 20 mp(.md5_file(12).);../*.NULL.as.
03c0 66 69 6c 65 6e 61 6d 65 20 2a 2f 0a 76 61 72 5f 64 75 6d 70 28 20 6d 64 35 5f 66 69 6c 65 28 4e filename.*/.var_dump(.md5_file(N
03e0 55 4c 4c 29 20 29 3b 0a 0a 2f 2a 20 5a 65 72 6f 20 61 72 67 75 6d 65 6e 74 73 20 2a 2f 0a 20 76 ULL).);../*.Zero.arguments.*/..v
0400 61 72 5f 64 75 6d 70 20 28 20 6d 64 35 5f 66 69 6c 65 28 29 20 29 3b 0a 0a 2f 2a 20 4d 6f 72 65 ar_dump.(.md5_file().);../*.More
0420 20 74 68 61 6e 20 76 61 6c 69 64 20 6e 75 6d 62 65 72 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 20 .than.valid.number.of.arguments.
0440 28 20 76 61 6c 69 64 20 69 73 20 32 29 20 20 2a 2f 0a 76 61 72 5f 64 75 6d 70 20 28 20 6d 64 35 (.valid.is.2)..*/.var_dump.(.md5
0460 5f 66 69 6c 65 28 22 45 6d 70 74 79 46 69 6c 65 4d 44 35 2e 74 78 74 22 2c 20 74 72 75 65 2c 20 _file("EmptyFileMD5.txt",.true,.
0480 4e 55 4c 4c 29 20 29 3b 0a 0a 2f 2a 20 48 65 78 61 64 65 63 69 6d 61 6c 20 4f 75 74 70 75 74 20 NULL).);../*.Hexadecimal.Output.
04a0 66 6f 72 20 45 6d 70 74 79 20 66 69 6c 65 20 61 73 20 69 6e 70 75 74 20 2a 2f 0a 65 63 68 6f 20 for.Empty.file.as.input.*/.echo.
04c0 22 5c 6e 2a 2a 2a 20 48 65 78 61 64 65 63 69 6d 61 6c 20 4f 75 74 70 75 74 20 66 6f 72 20 45 6d "\n***.Hexadecimal.Output.for.Em
04e0 70 74 79 20 66 69 6c 65 20 61 73 20 41 72 67 75 6d 65 6e 74 20 2a 2a 2a 5c 6e 22 3b 0a 76 61 72 pty.file.as.Argument.***\n";.var
0500 5f 64 75 6d 70 28 20 6d 64 35 5f 66 69 6c 65 28 22 45 6d 70 74 79 46 69 6c 65 4d 44 35 2e 74 78 _dump(.md5_file("EmptyFileMD5.tx
0520 74 22 29 20 29 3b 0a 0a 2f 2a 20 52 61 77 20 42 69 6e 61 72 79 20 4f 75 74 70 75 74 20 66 6f 72 t").);../*.Raw.Binary.Output.for
0540 20 45 6d 70 74 79 20 66 69 6c 65 20 61 73 20 69 6e 70 75 74 20 2a 2f 0a 65 63 68 6f 20 22 5c 6e .Empty.file.as.input.*/.echo."\n
0560 2a 2a 2a 20 52 61 77 20 42 69 6e 61 72 79 20 4f 75 74 70 75 74 20 66 6f 72 20 45 6d 70 74 79 20 ***.Raw.Binary.Output.for.Empty.
0580 66 69 6c 65 20 61 73 20 41 72 67 75 6d 65 6e 74 20 2a 2a 2a 5c 6e 22 3b 0a 76 61 72 5f 64 75 6d file.as.Argument.***\n";.var_dum
05a0 70 28 20 6d 64 35 5f 66 69 6c 65 28 22 45 6d 70 74 79 46 69 6c 65 4d 44 35 2e 74 78 74 22 2c 20 p(.md5_file("EmptyFileMD5.txt",.
05c0 74 72 75 65 29 20 29 3b 0a 0a 2f 2a 20 4e 6f 72 6d 61 6c 20 6f 70 65 72 61 74 69 6f 6e 20 77 69 true).);../*.Normal.operation.wi
05e0 74 68 20 68 65 78 61 64 65 63 69 6d 61 6c 20 6f 75 74 70 75 74 20 2a 2f 0a 65 63 68 6f 20 22 5c th.hexadecimal.output.*/.echo."\
0600 6e 2a 2a 2a 20 48 65 78 61 64 65 63 69 6d 61 6c 20 4f 75 74 70 75 74 20 66 6f 72 20 61 20 76 61 n***.Hexadecimal.Output.for.a.va
0620 6c 69 64 20 66 69 6c 65 20 77 69 74 68 20 73 6f 6d 65 20 63 6f 6e 74 65 6e 74 73 20 2a 2a 2a 5c lid.file.with.some.contents.***\
0640 6e 22 3b 0a 76 61 72 5f 64 75 6d 70 28 20 6d 64 35 5f 66 69 6c 65 28 22 44 61 74 61 46 69 6c 65 n";.var_dump(.md5_file("DataFile
0660 4d 44 35 2e 74 78 74 22 29 20 29 3b 0a 0a 2f 2a 20 4e 6f 72 6d 61 6c 20 6f 70 65 72 61 74 69 6f MD5.txt").);../*.Normal.operatio
0680 6e 20 77 69 74 68 20 72 61 77 20 62 69 6e 61 72 79 20 6f 75 74 70 75 74 20 2a 2f 0a 65 63 68 6f n.with.raw.binary.output.*/.echo
06a0 20 22 5c 6e 2a 2a 2a 20 52 61 77 20 42 69 6e 61 72 79 20 4f 75 74 70 75 74 20 66 6f 72 20 61 20 ."\n***.Raw.Binary.Output.for.a.
06c0 76 61 6c 69 64 20 66 69 6c 65 20 77 69 74 68 20 73 6f 6d 65 20 63 6f 6e 74 65 6e 74 73 20 2a 2a valid.file.with.some.contents.**
06e0 2a 5c 6e 22 3b 0a 76 61 72 5f 64 75 6d 70 20 28 20 6d 64 35 5f 66 69 6c 65 28 22 44 61 74 61 46 *\n";.var_dump.(.md5_file("DataF
0700 69 6c 65 4d 44 35 2e 74 78 74 22 2c 20 74 72 75 65 29 20 29 3b 0a 0a 2f 2f 20 72 65 6d 6f 76 65 ileMD5.txt",.true).);..//.remove
0720 20 74 65 6d 70 20 66 69 6c 65 73 0a 75 6e 6c 69 6e 6b 28 22 44 61 74 61 46 69 6c 65 4d 44 35 2e .temp.files.unlink("DataFileMD5.
0740 74 78 74 22 29 3b 0a 75 6e 6c 69 6e 6b 28 22 45 6d 70 74 79 46 69 6c 65 4d 44 35 2e 74 78 74 22 txt");.unlink("EmptyFileMD5.txt"
0760 29 3b 0a 0a 65 63 68 6f 20 22 5c 6e 44 6f 6e 65 22 3b 0a 3f 3e 0a 2d 2d 45 58 50 45 43 54 46 2d );..echo."\nDone";.?>.--EXPECTF-
0780 2d 0a 2a 2a 2a 20 54 65 73 74 69 6e 67 20 66 6f 72 20 65 72 72 6f 72 20 63 6f 6e 64 69 74 69 6f -.***.Testing.for.error.conditio
07a0 6e 73 20 2a 2a 2a 0a 0a 57 61 72 6e 69 6e 67 3a 20 6d 64 35 5f 66 69 6c 65 28 29 3a 20 46 69 6c ns.***..Warning:.md5_file():.Fil
07c0 65 6e 61 6d 65 20 63 61 6e 6e 6f 74 20 62 65 20 65 6d 70 74 79 20 69 6e 20 25 73 20 6f 6e 20 6c ename.cannot.be.empty.in.%s.on.l
07e0 69 6e 65 20 25 64 0a 62 6f 6f 6c 28 66 61 6c 73 65 29 0a 0a 57 61 72 6e 69 6e 67 3a 20 6d 64 35 ine.%d.bool(false)..Warning:.md5
0800 5f 66 69 6c 65 28 61 5a 72 71 31 36 75 29 3a 20 66 61 69 6c 65 64 20 74 6f 20 6f 70 65 6e 20 73 _file(aZrq16u):.failed.to.open.s
0820 74 72 65 61 6d 3a 20 4e 6f 20 73 75 63 68 20 66 69 6c 65 20 6f 72 20 64 69 72 65 63 74 6f 72 79 tream:.No.such.file.or.directory
0840 20 69 6e 20 25 73 20 6f 6e 20 6c 69 6e 65 20 25 64 0a 62 6f 6f 6c 28 66 61 6c 73 65 29 0a 0a 57 .in.%s.on.line.%d.bool(false)..W
0860 61 72 6e 69 6e 67 3a 20 6d 64 35 5f 66 69 6c 65 28 31 32 29 3a 20 66 61 69 6c 65 64 20 74 6f 20 arning:.md5_file(12):.failed.to.
0880 6f 70 65 6e 20 73 74 72 65 61 6d 3a 20 4e 6f 20 73 75 63 68 20 66 69 6c 65 20 6f 72 20 64 69 72 open.stream:.No.such.file.or.dir
08a0 65 63 74 6f 72 79 20 69 6e 20 25 73 20 6f 6e 20 6c 69 6e 65 20 25 64 0a 62 6f 6f 6c 28 66 61 6c ectory.in.%s.on.line.%d.bool(fal
08c0 73 65 29 0a 0a 57 61 72 6e 69 6e 67 3a 20 6d 64 35 5f 66 69 6c 65 28 29 3a 20 46 69 6c 65 6e 61 se)..Warning:.md5_file():.Filena
08e0 6d 65 20 63 61 6e 6e 6f 74 20 62 65 20 65 6d 70 74 79 20 69 6e 20 25 73 20 6f 6e 20 6c 69 6e 65 me.cannot.be.empty.in.%s.on.line
0900 20 25 64 0a 62 6f 6f 6c 28 66 61 6c 73 65 29 0a 0a 57 61 72 6e 69 6e 67 3a 20 6d 64 35 5f 66 69 .%d.bool(false)..Warning:.md5_fi
0920 6c 65 28 29 20 65 78 70 65 63 74 73 20 61 74 20 6c 65 61 73 74 20 31 20 70 61 72 61 6d 65 74 65 le().expects.at.least.1.paramete
0940 72 2c 20 30 20 67 69 76 65 6e 20 69 6e 20 25 73 20 6f 6e 20 6c 69 6e 65 20 25 64 0a 4e 55 4c 4c r,.0.given.in.%s.on.line.%d.NULL
0960 0a 0a 57 61 72 6e 69 6e 67 3a 20 6d 64 35 5f 66 69 6c 65 28 29 20 65 78 70 65 63 74 73 20 61 74 ..Warning:.md5_file().expects.at
0980 20 6d 6f 73 74 20 32 20 70 61 72 61 6d 65 74 65 72 73 2c 20 33 20 67 69 76 65 6e 20 69 6e 20 25 .most.2.parameters,.3.given.in.%
09a0 73 20 6f 6e 20 6c 69 6e 65 20 25 64 0a 4e 55 4c 4c 0a 0a 2a 2a 2a 20 48 65 78 61 64 65 63 69 6d s.on.line.%d.NULL..***.Hexadecim
09c0 61 6c 20 4f 75 74 70 75 74 20 66 6f 72 20 45 6d 70 74 79 20 66 69 6c 65 20 61 73 20 41 72 67 75 al.Output.for.Empty.file.as.Argu
09e0 6d 65 6e 74 20 2a 2a 2a 0a 73 74 72 69 6e 67 28 33 32 29 20 22 64 34 31 64 38 63 64 39 38 66 30 ment.***.string(32)."d41d8cd98f0
0a00 30 62 32 30 34 65 39 38 30 30 39 39 38 65 63 66 38 34 32 37 65 22 0a 0a 2a 2a 2a 20 52 61 77 20 0b204e9800998ecf8427e"..***.Raw.
0a20 42 69 6e 61 72 79 20 4f 75 74 70 75 74 20 66 6f 72 20 45 6d 70 74 79 20 66 69 6c 65 20 61 73 20 Binary.Output.for.Empty.file.as.
0a40 41 72 67 75 6d 65 6e 74 20 2a 2a 2a 0a 73 74 72 69 6e 67 28 31 36 29 20 22 d4 1d 8c d9 8f 00 b2 Argument.***.string(16).".......
0a60 04 e9 80 09 98 ec f8 42 7e 22 0a 0a 2a 2a 2a 20 48 65 78 61 64 65 63 69 6d 61 6c 20 4f 75 74 70 .......B~"..***.Hexadecimal.Outp
0a80 75 74 20 66 6f 72 20 61 20 76 61 6c 69 64 20 66 69 6c 65 20 77 69 74 68 20 73 6f 6d 65 20 63 6f ut.for.a.valid.file.with.some.co
0aa0 6e 74 65 6e 74 73 20 2a 2a 2a 0a 73 74 72 69 6e 67 28 33 32 29 20 22 37 66 32 38 65 63 36 34 37 ntents.***.string(32)."7f28ec647
0ac0 38 32 35 65 32 61 37 30 62 66 36 37 37 37 38 34 37 32 63 64 34 61 32 22 0a 0a 2a 2a 2a 20 52 61 825e2a70bf67778472cd4a2"..***.Ra
0ae0 77 20 42 69 6e 61 72 79 20 4f 75 74 70 75 74 20 66 6f 72 20 61 20 76 61 6c 69 64 20 66 69 6c 65 w.Binary.Output.for.a.valid.file
0b00 20 77 69 74 68 20 73 6f 6d 65 20 63 6f 6e 74 65 6e 74 73 20 2a 2a 2a 0a 73 74 72 69 6e 67 28 31 .with.some.contents.***.string(1
0b20 36 29 20 22 7f 28 ec 64 78 25 e2 a7 0b f6 77 78 47 2c d4 a2 22 0a 0a 44 6f 6e 65 0a 6).".(.dx%....wxG,.."..Done.