itisme Posted August 16, 2007 Share Posted August 16, 2007 My buddy sent me a php script to extract MD5 hashes from a text file. I can see the references for hashes.txt however I am unsure how to submit. Ideally I would like to use an HTML forum to submit txt file. I have to parts to the script: 1: <?php // sunjester // - Email address removed from bots quote post to view - // www.hgsdomination.com function strip_md5($str){ $words = 0; $str = eregi_replace(" +", " ", $str); $array = explode(" ", $str); for($i=0;$i < count($array);$i++) { if (eregi("[0-9A-Za-zÀ-ÖØ-öø-ÿ]", $array[$i])) $words++; $checklen = strlen($array[$i]); if($checklen == "32") { echo $array[$i]."<br>"; } } return $words; } ?> and 2. <?php $filename = "hashes.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); $test = $contents; echo strip_md5($test)." words available<hr>"; echo strip_md5($test)." words available<hr>"; ?> Any help would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/65234-web-form/ Share on other sites More sharing options...
php_tom Posted August 16, 2007 Share Posted August 16, 2007 I guess you mean that you want to post the MD5 stuff in a web form instead of needing to edit the text file... although sending even md5s of stuff over the web is not too secure, there are md5 crackers out there... but here's what I'd do: <?php if($_POST['text'] != "") { $contents = strip_tags($_POST['text']); $test = $contents; echo strip_md5($test)." words available<hr>"; echo strip_md5($test)." words available<hr>"; } else { // Print the form... echo "<form action='thisPage.php' method='post'><textarea rows='20' cols='30' name='text'>"; echo "</textarea><input type='submit' value='DO MD5 Stuff!' /></form>"; } // sunjester // - Email address removed from bots quote post to view - // www.hgsdomination.com function strip_md5($str){ $words = 0; $str = eregi_replace(" +", " ", $str); $array = explode(" ", $str); for($i=0;$i < count($array);$i++) { if (eregi("[0-9A-Za-zÀ-ÖØ-öø-ÿ]", $array[$i])) $words++; $checklen = strlen($array[$i]); if($checklen == "32") { echo $array[$i]."<br>"; } } return $words; } ?> Try this (and change the 'thisPage.php' to the name of your script...) Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/65234-web-form/#findComment-325759 Share on other sites More sharing options...
itisme Posted August 16, 2007 Author Share Posted August 16, 2007 I am just looking to create a forum to upload a text file and return MD5s. It will be run inside our LAN so security is not to big of an issue. I am looking to upload a .txt file and have the MD5s hashes extracted Quote Link to comment https://forums.phpfreaks.com/topic/65234-web-form/#findComment-325762 Share on other sites More sharing options...
php_tom Posted August 16, 2007 Share Posted August 16, 2007 Try this (sorry its long but i think it's what you want): In "upload.html": <form enctype="multipart/form-data" action="upload_2.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="10000000" /> <!-- 10MB --> File: <input name="userfile" type="file" /><br /> <center><input type="submit" value="Upload" /></center> </form> Then in "upload2.php": <?php $name = $_FILES['userfile']['name']; $size = $_FILES['userfile']['size']; $type = $_FILES['userfile']['type']; if(!uploadFile($name,"theFolderYouWantTheFileIn")) die("The file couldn't be uploaded. Please contact your network administrator."); $filename = "theFolderYouWantTheFileIn/".$name; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); $test = $contents; echo strip_md5($test)." words available<hr>"; echo strip_md5($test)." words available<hr>"; function uploadFile($name,$folder) { $filename=$_FILES['userfile']['name']; $filesize=$_FILES['userfile']['size']; $tempname=$_FILES['userfile']['tmp_name']; $fullname=$folder."/".$filename; copy($tempname, $fullname) or return false; return true; } function strip_md5($str){ $words = 0; $str = eregi_replace(" +", " ", $str); $array = explode(" ", $str); for($i=0;$i < count($array);$i++) { if (eregi("[0-9A-Za-zÀ-ÖØ-öø-ÿ]", $array[$i])) $words++; $checklen = strlen($array[$i]); if($checklen == "32") { echo $array[$i]."<br>"; } } return $words; } ?> Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/65234-web-form/#findComment-325794 Share on other sites More sharing options...
itisme Posted August 16, 2007 Author Share Posted August 16, 2007 Thanks, that exactly what I'm looking for. I get the following error while trying to upload file: Parse error: parse error, unexpected T_RETURN in /var/www/html/12/upload_2.php on line 20 and line 20 is: copy($tempname, $fullname) or return false; any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/65234-web-form/#findComment-325898 Share on other sites More sharing options...
php_tom Posted August 16, 2007 Share Posted August 16, 2007 Try replacing the function with function uploadFile($name,$folder) { $filename=$_FILES['userfile']['name']; $filesize=$_FILES['userfile']['size']; $tempname=$_FILES['userfile']['tmp_name']; $fullname=$folder."/".$filename; copy($tempname, $fullname) or die("Cannot upload file!"); return true; } Post back if that doesn't work... Quote Link to comment https://forums.phpfreaks.com/topic/65234-web-form/#findComment-325960 Share on other sites More sharing options...
itisme Posted August 16, 2007 Author Share Posted August 16, 2007 thanks for the reply, but I am getting the exact same error Quote Link to comment https://forums.phpfreaks.com/topic/65234-web-form/#findComment-325991 Share on other sites More sharing options...
php_tom Posted August 16, 2007 Share Posted August 16, 2007 Maybe this is the problem? $fullname=$folder."/".$filename; I don't think we defined $folder anywhere... Try changing it to $fullname="theFolderYouWantTheUploadsIn/".$filename; Quote Link to comment https://forums.phpfreaks.com/topic/65234-web-form/#findComment-326044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.