usapphire Posted February 19, 2007 Share Posted February 19, 2007 Hello everyone! I was just searching the forums for "upload" so I could see some examples of a script I'm looking to make - however, there didn't seem to be any at all of what I was looking for This is going to sound a bit bad, because I'm requesting for a script (or a tutorial to something similar), so I apologize in advanced, but I've been looking through google and hotscripts.com for the past 2 weeks.. What I want is two scripts. First, the Upload Script: - Any file extention, no file size limit. - When pressing "upload", a progress bar is shown / the upload button is grayed out. - The website I want to use it for has 6 different sections, so I want the script to be able to be customized to choose where I want the file to be uploaded. The download script: - A script that can be easily integrated to my current website design - Shows all files that are in a directory (except thumbs.whatever and the "." and ".." folders). - Shows the file size in Megabytes. This script will be used on a free uploading site, but what I've done is split the site into 6 different categories (for example "Images" "Videos" "Software", (only examples) etc). If someone can point me into the right direction for tutorials for this, I'd be very grateful.. For those who can make it for me, or help me with it, I'm willing to either pay real money through Bank Deposit, or give you a free shared hosting server from www.hostanime.net (I'll buy it for you, but you gotta include a domain). Thank you, and I'm so very sorry if this is asking for too much.. Have a great February! I've also got MSN Messenger for those who ask. Thank you again!! Quote Link to comment Share on other sites More sharing options...
xyn Posted February 19, 2007 Share Posted February 19, 2007 I had a tutorial which allows you to upload images to a MYSQL, this wasnt very secure btw but you could download them etc. However A more simelar way would be uploading and moving to a directory, htaccess the file to remove indexes, and then you can also allow downloading by using MYSQL Database by storing the files ID code. which i suggest you rename the files. Basically This is one of my OLD scripts, so feel free to use it and learn it function UploadAvatar(){ if(isset($_POST['avatar']) && empty($_POST['avatar'])) { echo "<p><span class=\"heading\">Error:</span><br> <span class=\"error\">You have left your avatar upload blank, please select an image 90 x 90 to upload.</span></p>"; return false; } else { $upload_dir="./global/images/private"; $upload_dir .= $folder; $upload_dir .= "/"; $max_size = "102400"; $file_types = array( 'image/pjpeg' => 'jpg', 'image/jpeg' => 'jpg', 'image/jpeg' => 'jpeg', 'image/gif' => 'gif', 'image/X-PNG' => 'png', 'image/PNG' => 'png', 'image/png' => 'png', 'image/x-png' => 'png', 'image/JPG' => 'jpg', 'image/GIF' => 'gif', 'image/bmp' => 'bmp', 'image/bmp' => 'BMP', ); $filesize = MakeSafe($_FILES['avatar']['size']); $filetype = MakeSafe($_FILES['avatar']['type']); if ($filesize > $max_size) { echo "<p><span class=\"heading\">Error:</span><br> <span class=\"error\">Your avatar is to big, please select a smaller image.</span></p>"; return false; } if (!array_key_exists($filetype, $file_types)) { echo "<p><span class=\"heading\">Error:</span><br> <span class=\"error\">Your avatar is not the correct format, please change it.</span></p>"; return false; } else { $sql = mysql_query("SELECT filename FROM avatar WHERE user='{$_SESSION['username']['usr_user']}'"); while( $data = mysql_fetch_array( $sql, MYSQL_NUM )) { $av_name = "./global/images/private/".$data[0].""; } if(file_exists($av_name)) { unlink($av_name); } $new_file = substr(sha1(rand(11, time())), 0, . '.' . $file_types[$filetype]; if (move_uploaded_file(MakeSafe($_FILES['avatar']['tmp_name']), $upload_dir . $new_file)) { $filename=$new_file; } // //Check Diametre // //$PicUrl = ""; $size = @getimagesize("http://www.eumod.co.uk/en/global/images/private/".$filename.""); $height = $size[1]; $width = $size[0]; if( $height >90 || $width >90) { echo "<p><span class=\"heading\">Error:</span><br> <span class=\"error\">Your avatar is not the correct diameter, please change it to 90 x 90 pixels.</span></p>"; return false; } $SQL = mysql_query("SELECT * FROM avatar WHERE user='{$_SESSION['username']['usr_user']}'"); $NUM = mysql_num_rows( $SQL ); $date = date("d F, o"); $time = date("g:ia"); if( !$NUM ) { mysql_query("INSERT INTO avatar (user, filename, date, time) VALUES ('{$_SESSION['username']['usr_user']}', '".$new_file."', '$date', '$time')") or die('Error: '.mysql_error().''); echo "<p><span class=\"heading\">Avatar Uploaded</span><br> <span class=\"text\">your avatar has been uploaded, the change should take imediate effects.</span></p>"; } else { mysql_query("UPDATE avatar SET filename='".MakeSafe($new_file)."', date='$date', time='$time' WHERE user='{$_SESSION['username']['usr_user']}'"); echo "<p><span class=\"heading\">Avatar Uploaded</span><br> <span class=\"text\">your avatar has been uploaded, the change should take imediate effects.</span></p>"; } } } return true; } Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 19, 2007 Author Share Posted February 19, 2007 I'm very, very noob with PHP at the moment - I've only designed websites in HTML and used <php include>.. That's about it I had a look at the script you posted and didn't really understand it much.. I could customize some things in there and understand, but other things just look really confusing to me I'm so sorry for asking this :'( Quote Link to comment Share on other sites More sharing options...
xyn Posted February 19, 2007 Share Posted February 19, 2007 ok, well i'll cut it down for you... <?php /************ * Lets check if the upload field * has actually been filled in *************/ if(isset($_POST['avatar']) && empty($_POST['avatar'])) { //They was not set //So we will show //this message and //kill the script. die("Please select a file you wish to upload."); } else { //Now they have filled in //The form with their file //you can now check if its //an image. //Set the Directory where you //want the files to upload to $upload_dir="uploads"; $upload_dir .= $folder; $upload_dir .= "/"; $max_size = "102400"; //1 MB //Loop the file types //using an array $file_types = array( 'image/pjpeg' => 'jpg', 'image/jpeg' => 'jpg', 'image/jpeg' => 'jpeg', 'image/gif' => 'gif', 'image/X-PNG' => 'png', 'image/PNG' => 'png', 'image/png' => 'png', 'image/x-png' => 'png', 'image/JPG' => 'jpg', 'image/GIF' => 'gif', 'image/bmp' => 'bmp', 'image/bmp' => 'BMP', ); //Lets make sure that the file //is within the limit, and that //it is an image. $filesize = $_FILES['avatar']['size']; $filetype = $_FILES['avatar']['type']; if($filesize > $max_size) { //Too big, lets tell them //and kill the script die("too big, choose a smaller image, or shrink your current one"); } if (!array_key_exists($filetype, $file_types)) { //the file type doesnt match //anything in that array above //so that means it isnt an image //tell them, kill the script. die("You can only upload images"); } //Time to actually rename the file //then uplaod the file name to a SQL //and make sure the images are moved //to your folder which is CHMOD 0777 (permissions) $new_file = substr(sha1(rand(11, time())), 0, . '.' . $file_types[$filetype]; if (move_uploaded_file(MakeSafe($_FILES['avatar']['tmp_name']), $upload_dir . $new_file)) { $filename=$new_file; } //Make sure you have a database set-up //and make the correct tables, or edit //the query to specify your own tables. include("config.php"); //MYSQL Connections mysql_query("INSERT INTO `images` (`filename`,`filetype`,`date`,`ip`) VALUES ('".$newname."', '".$filetype."', '".date("j/m/Y, H:i:s")."', '".getenv('REMOTE_ADDR')."')"); echo ("uploaded successful"); } ?> Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 19, 2007 Author Share Posted February 19, 2007 Hi, thank you! That helps So how do I merge that with a form so they can upload? Also, how do I display the files for download? ??? Thanks again! Quote Link to comment Share on other sites More sharing options...
xyn Posted February 19, 2007 Share Posted February 19, 2007 make sure you have your upload form, and name it avatar.. here is a temp code, as im nice. make thatcode above upload.php and this form can be edited to your pleasure <form method="POST" action="upload.php" enctype="multipart/form-data"> <div align="center"> <center> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#009500" width="400" bgcolor="#CCFFCC"> <tr> <td width="100%"><font size="6"><b>Upload<br> </b></font><font size="2">Upload your images here.</font><p> <input type="file" name="avatar" size="20"><br> <input type="submit" value="Upload" name="submit"></p> </td> </tr> </table> </center> </div> </form> Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 19, 2007 Author Share Posted February 19, 2007 Wow! Thank you so much! It works great! Is there someway to grey-out the Upload button when clicked, so they know it's being uploaded? Also, I know you've helped me a lot, but are you able to help me with the download script? If not, can you point me to somewhere? Thanks again!! Quote Link to comment Share on other sites More sharing options...
xyn Posted February 19, 2007 Share Posted February 19, 2007 Ok then, put the Javascript in the <HEAD></HEAD> tags, anywhere between them then you need to do this on your form add this at the end... onSubmit="submitonce(this)" JAVASCRIPT <script> function submitonce(theform){ if (document.all||document.getElementById){ for (i=0;i<theform.length;i++){ var tempobj=theform.elements[i] if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") tempobj.disabled=true } } } </script> Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 19, 2007 Author Share Posted February 19, 2007 Yay! Thank you.. it works and it runs great!! All I need now is a little help with the download script.. Quote Link to comment Share on other sites More sharing options...
xyn Posted February 19, 2007 Share Posted February 19, 2007 that's easy. Once you have got the database set-up. you can loop an array, list the items, and then make a link to the file Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 19, 2007 Author Share Posted February 19, 2007 Is there a tutorial for this? I set up the mysql already with the script you posted (for a test for now), but I don't know anything about looping an array and listing the items.. And how do I link to the file if every file is different? Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 19, 2007 Author Share Posted February 19, 2007 Found one.. Thanks again for your help! For everyone else who wants to know: <? $file_dir="FILE_DIRECTORY"; $dir=opendir($file_dir); while ($file=readdir($dir)) { if ($file != "." && $file != "..") { echo "<a href=".$file_dir."/".$file." target=_blank>".$file."</a>"; echo "<br>"; } } ?> Quote Link to comment 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.