#18770 - 11/25/08 11:45 AM
Script Help
|
Quadrohs
Malt-o-Meal
Registered: 11/19/08
Posts: 5
Loc: Canada
|
Offline
|
|
Im working on a image file upload for the Player Avatars and Forum avatars. It works allright at the moment but I need to add a check to make sure it dosent overwrite a file allready in the upload folder! If anyone could help out with this script I think it would be a good MOD for the Game and I can get it posted in the MOD index.
Any way this script is for the forums! first you need to add `forumavatar` varchar(10) NOT NULL default '0'; to the forum and users table and use this as the upload script.
// START OF THE FORUM AVATAR FUNCTION function avatar() { global $userrow, $numqueries; // List Files $file_dir = "images/forumavatars/"; // SETS THE PATH TO THE BULLITIN AVATAR FOLDER. $handle = opendir($file_dir); $filelist = ""; while ($file = readdir($handle)) { if (!is_dir($file) && !is_link($file)) { $filelist .= "<a href='$file_dir$file' target=_blank alt='$file'>$file <img src=images/forumavatars/$file width=50 height=50></a> "; } } if (isset($_POST['avatar'])) { $avatar = $_POST['address']; doquery("UPDATE {{table}} SET forumavatar='$avatar' WHERE id='".$userrow["id"]."' LIMIT 1", "users"); } $page = "<table width=100% align=center border=1><tr><td class=title align=center>Change Your Bullitin Avatar</td></tr><tr><td align=center>"; $page .= "Go back to the <a href=bullitin.php>Bullitin Board</a><br />"; $page .= "<form action='bullitin.php?do=avupload' method='post' enctype='multipart/form-data'><p>"; // DELETE THIS LINE IF YOU DONT WISH TO ALLOW UPLOADS OR PUT LIKE THIS // IN FRONT OF THIS LINE, THEN YOU CAN JUST REMOVE THE // TO GET THE UPLOAD OPTION BACK $page .= "<label for='file'><strong>Select and Upload Your Bullitin Avatar</strong></label><br /><br />Avatar Images should be no larger then 50 x 50 Pixels and 1 mb in size.<br />"; // DELETE THIS LINE IF YOU DONT WISH TO ALLOW UPLOADS OR PUT LIKE THIS // IN FRONT OF THIS LINE, THEN YOU CAN JUST REMOVE THE // TO GET THE UPLOAD OPTION BACK $page .= "<input type='file' name='userfile' id='file' size=50><br /><input type='submit' value='Upload Avatar' /><p></form>"; // DELETE THIS LINE IF YOU DONT WISH TO ALLOW UPLOADS OR PUT LIKE THIS // IN FRONT OF THIS LINE, THEN YOU CAN JUST REMOVE THE // TO GET THE UPLOAD OPTION BACK $page .= "<table><tr><td align=center>"; $page .= "Current<br /><img src=images/forumavatars/".$userrow["forumavatar"]." width=50 height=50 border=1><br />Avatar"; $page .= "</td><td align=center>"; $page .= "<form action=bullitin.php?do=avatar method=post>"; $page .= "Avatar Name<br /><input type=text value='' name=address size=50><br />"; $page .= "<input type=submit value='Change My Avatar' name=avatar></form><br />"; $page .= "<strong>! Or use a Avatar from the Gallery !</strong><br />"; $page .= "<strong>! Avatar Name is left of the Avatar Picture !</strong><br />"; $page .= "</td></tr></table>"; $page .= "<hr width=70%>"; $page .= "$filelist"; $page .= "<hr width=70%>"; $page .= "</td></tr></table>"; display($page, "Change Bullitin Avatars"); } // END OF THE FORUM AVATAR FUNCTION
// START OF THE FORUM AVATAR UPLOAD FUNCTION function avupload() { global $userrow, $numqueries; $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // TYPES OF FILES THAT CAN BE UPLOADED. $max_filesize = 1048576; // MAXIMUM FILE SIZE TO BE UPLOADED IN BYTES, CURRENTLY ( 1.0 MBs ). $upload_path = './images/forumavatars/'; // SETS THE PATH TO THE AVATAR FOLDER, FILES WILL BE UPLOADED TO THIS FOLDER. $filename = $_FILES['userfile']['name']; $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); if (!in_array($ext,$allowed_filetypes)) { // CHECK TO ENSURE FILE TYPE IS ALLOWED, IF NOT DIE AND INFORM USER. display("<table width=100% align=center border=1><tr><td>The file you attempted to upload is not allowed.</td></tr></table>", "Error"); die(); } if (filesize($_FILES['userfile']['tmp_name']) > $max_filesize) { // CHECK THE FILESIZE, IF ITS TO LARGE THEN DIE AND INFORM USER. display("<table width=100% align=center border=1><tr><td>The file you attempted to upload is too large.</td></tr></table>", "Error"); die(); } if (!is_writable($upload_path)) { // CHECK TO ENSURE PROPER UPLOAD FOLDER, IF NOT DIE AND INFORM USER. display("<table width=100% align=center border=1><tr><td>You cannot upload to the specified directory.</td></tr></table>", "Error"); die(); } if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) { $page = "<table width=100% align=center border=1><tr><td class=title align=center>Bullitin Avatar Upload</td></tr><tr><td align=center>"; $page .= "<center>Go back to the <a href=bullitin.php>Bullitin Board</a><br /><br />"; $page .= "Your file upload was successful, view the file <a href=\"$upload_path$filename\" title=\"Your File\" target=\"_blank\">here</a><br />"; $page .= "<br />Go back to <a href=\"bullitin.php?do=avatar\">change</a> your forum avatar.</center>"; $page .= "</td></tr></table>"; display($page, "Change avatar"); } else { $page = "<table width=100% align=center border=1><tr><td class=title align=center>Bullitin Avatar Upload</td></tr><tr><td align=center>"; $page .= "<center>Go back to the <a href=index.php>city gates</a><br /><br />"; $page .= "There was an error during the file upload, Please try again.<br />"; $page .= "<br />Go back to the <a href=\"bullitin.php?do=avatar\">change your forum avatar</a></center>"; $page .= "</td></tr></table>"; display($page, "Upload Bullitin Avatars"); } } // END OF THE FORUM AVATAR UPLOAD FUNCTION
If anyone can get it too not overwrite existing files I will upload my whole forum. It has stikies, locking threads, # of views, emoticons, avatars and avatar gallery and a full admin function for editing and deleting posts and users can do some editing of there own posts as well. In game Mail to let you know someone replied to your post as well.
It all works good accept I cant get it to not overwrite existing files when uploading a new avatar.
Any help would be much appreciated.
Oh I call my Foum Bullitin so you may want to change any Bullitin to forum.
Edited by Quadrohs (11/25/08 11:48 AM)
|
|
Top
|
|
|
|
|