usapphire Posted February 21, 2007 Share Posted February 21, 2007 Hey everyone Thanks previously for your help! I have a quick problem, which I'm sure is just something very silly.. I made an upload script thanks to PHP Freaks and the person who replied to my previous forum, but after finally finishing it.. there seemed to be an error. Okay, so this is what I did: 1. Script worked fine. Integrated into the site layout with no problem. 2. Made "categories" within the site.. So this means that there is more than 1 upload/download page.* 3. Made the MySQL databases to hold data for the other categories. 4. Uploaded the new pages, and CHMOD the upload folder to 777. 5. Tried it out - doesn't work anymore. * The different categories are on different pages. For example; category1.php, category2.php, etc. Here is the code I'm using. Upload form / display download files page. <?php include("header.php"); ?> <div align="center"><img src="images/index_category1.jpg" border="0"></div><br> <?php $uploadDir = 'category1/upload/'; if(isset($_POST['upload'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; // get the file extension first $ext = substr(strrchr($fileName, "."), 1); // make the random file name $randName = md5(rand() * time()); // and now we have the unique file name for the upload file $filePath = $uploadDir . $randName . '.' . $ext; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "There was an error uploading the file. Click the back button and try again."; exit; } include 'category1/config.php'; include 'category1/opendb.php'; if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $query = "INSERT INTO upload2 (name, size, type, path ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); include 'category1/closedb.php'; echo "<div align=center><font color=red><b>YOUR FILE HAS BEEN UPLOADED!</b><br></div></font>The Direct link is found on the right of your file name. Can't see your file? New uploaded files are placed on the bottom of the list, so scroll down. To copy the link, Right-Click on the <b>DOWNLOAD FILE</b> text, and select <b>Copy Link Location</b> or <b>Copy Shortcut</b>. Thank you for using our services!</font><br>"; } ?> <script> function showProgress(){document.getElementById('progressRow').style.display = 'inline'; } </script> <div align="center"> <span id="progressRow" style="display:none;"><table border=0 cellpadding=10 cellspacing=0 class=forText width=90%><tr><td valign=middle bgcolor=#ececec><div align=center><b><font color="black"><div align="center">Your file is being uploaded. Please wait <img src="images/dot.gif"></div></b></font></tr></td></table></span></div> <form method="post" enctype="multipart/form-data" onSubmit="submitonce(this)"> <table border="0" cellpadding="0" cellspacing="5" class="forText"> <tr> <td><img src="images/index_52.jpg"></td><td><input name="userfile" type="file" id="userfile" size="35" class="forText"> </td> <td><input name="upload" type="Submit" id="upload" value="Upload" onclick="showProgress();" onclick="this.disabled=true;"></td> </tr> </table> <div align="center"> <table border=0 cellpadding=10 cellspacing=0 class=forText width=90%><tr><td valign=middle bgcolor=#ececec><div align=center>-DISCLAIMER-</tr></td></table> </div> </form><br><br> <?php include("category1_download.php"); ?> <?php include("footer.php"); ?> The Download page (script for include) <?php error_reporting(E_ALL); if(isset($_GET['id'])) { include 'category1/config.php'; include 'category1/opendb.php'; $id = $_GET['id']; $query = "SELECT name, type, size, path FROM upload2 WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $filePath) = mysql_fetch_array($result); header("Content-Disposition: attachment; filename=$name"); header("Content-length: $size"); header("Content-type: $type"); readfile($filePath); include 'category1/closedb.php'; exit; } ?> <?php include 'category1/config.php'; include 'category1/opendb.php'; $query = "SELECT id, name FROM upload2"; $result = mysql_query($query) or die('Error, query failed'); if(mysql_num_rows($result) == 0) { echo "<div align=center><table border=0 cellpadding=5 cellspacing=0 class=forText width=90%><tr><td valign=middle bgcolor=#ececec><div align=center>There are no files uploaded in this directory. <b>Be the first!</b></tr></td></table></div>"; } else { while(list($id, $name) = mysql_fetch_array($result)) { ?> <table border=0 cellpadding=0 cellspacing=5 class=forText width=100%><tr><td valign=middle bgcolor=#ececec width=75><div align=center> <img src=images/category1.jpg></div></td><td valign=middle bgcolor=#ececec><div align=center><?=$name;?></div></td><td valign=middle bgcolor=#ececec width=100><div align=center><a href="category1_download.php?id=<?=$id;?>">DOWNLOAD FILE</a></div></tr></td></table> <?php } } include 'category1/closedb.php'; ?> The error that comes up is "There was an error uploading the file. Click the back button and try again." ??? Quote Link to comment Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 Make sure the upload dir exists. Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 21, 2007 Author Share Posted February 21, 2007 Yes, it does.. and it's CHMOD to 777 Thanks for trying to help Quote Link to comment Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 You can also try using my upload script posted here earlier: http://www.phpfreaks.com/forums/index.php/topic,127617.0.html Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 21, 2007 Author Share Posted February 21, 2007 You can also try using my upload script posted here earlier: http://www.phpfreaks.com/forums/index.php/topic,127617.0.html It's taken me over 5 hours just to get this one put together. I don't see a reason why it shouldn't work.. :'( If I can't find an explanation, I'll use yours.. Thank you for the post. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 21, 2007 Share Posted February 21, 2007 $ext = substr(strrchr($fileName, "."), 1); Shouldn't this be more like $ext = substr($fileName, strrpos($fileName, ".")); Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 21, 2007 Author Share Posted February 21, 2007 $ext = substr(strrchr($fileName, "."), 1); Shouldn't this be more like $ext = substr($fileName, strrpos($fileName, ".")); Changed, and it didn't seem to make a difference.. However, I found something that made the error. <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> This code is located in the header.php file between <HEAD></HEAD>. It's to prevent people from clicking "Upload" (submit button) more than once.. If I take it off, it works - but now I'm left with the Upload button still able to be clicked. Does anyone have another code that may allow it to work? Or know how I can change this one so it can work? Thank you EDIT: Just a note, it has actually worked in the past with the code!! Thanks again. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 21, 2007 Share Posted February 21, 2007 Why does it matter if they click it more than once? Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 21, 2007 Author Share Posted February 21, 2007 Why does it matter if they click it more than once? It's an upload site.. if they click it more than once, it'll restart the upload? I allowed files up to 100mb to be uploaded, so I don't think people who want to upload a file 100mb want to keep clicking it if they think it'll make it go fast.. :-\ Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 21, 2007 Share Posted February 21, 2007 If they think that, they deserve to wait as it goes over and over. Just like people who do that with elevators and traffic lights. Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 21, 2007 Author Share Posted February 21, 2007 If they think that, they deserve to wait as it goes over and over. Just like people who do that with elevators and traffic lights. Well ok.. thanks for the help. I'll try finding the answer somewhere.. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 21, 2007 Share Posted February 21, 2007 just add like: document.form_name.submit somewhere, i am pretty sure that would work. put it after the disabled submit button. Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 21, 2007 Author Share Posted February 21, 2007 just add like: document.form_name.submit somewhere, i am pretty sure that would work. put it after the disabled submit button. Sorry, should this go <input name="upload" type="Submit" id="upload" value="Upload" onclick="showProgress();" onclick="this.disabled=true;" HERE>? I don't understand. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 21, 2007 Share Posted February 21, 2007 like this: <input name="upload" type="Submit" id="upload" value="Upload" onclick="showProgress(); this.disabled=true; this.submit()"> i think, i am not to sure, javascript isnt my strong. Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 21, 2007 Author Share Posted February 21, 2007 like this: <input name="upload" type="Submit" id="upload" value="Upload" onclick="showProgress(); this.disabled=true; this.submit()"> i think, i am not to sure, javascript isnt my strong. It disables it, but still doesn't submit.. This is what's been happening.. Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 21, 2007 Author Share Posted February 21, 2007 No one knows? :'( Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 21, 2007 Share Posted February 21, 2007 instead of the this.submit try: document.your_form_name.submit() see if that works. Quote Link to comment Share on other sites More sharing options...
usapphire Posted February 21, 2007 Author Share Posted February 21, 2007 No, still doesn't work.. Thank you for trying to help, but I'll just remove it - if you happen to find the answer later, please let me know. Thank you. :'( 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.