Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload Script Gives Error

Status
Not open for further replies.

JamesCliff

Programmer
Feb 16, 2005
106
0
0
GB
Hi all,

Im using the following upload script to upload files into a directory on my web server. The script also adds a database entry at the same time for the filename.

However if i upload a file over about 800k i get an error saying the upload failed. This is the script im using:

Code:
<?php
$sectionid = $_GET["sectionid"];

$mysql = "SELECT * FROM brisk_downloads WHERE dl_section_id='$sectionid'";
$mysql_chk = mysql_query($mysql);
$mysqlfetch = mysql_fetch_array($mysql_chk);
$section_title = $mysqlfetch["title"];
?>
<table width="100%" align="center">
  <tr> 
    <td width="80%" height="131" valign="top"><div align="center">
        <p><br>
          <font color="#4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Add 
          Download to <? echo "$section_title"; ?></strong></font></p>
        <p>&nbsp;</p>
        <p> 
          <?php

DEFINE ('DB_USER', '*****');
DEFINE ('DB_PASSWORD', '*****');
DEFINE ('DB_HOST', '127.0.0.1');
DEFINE ('DB_NAME', 'briskfire');
mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR 
die ($message .= 'Could not connect to MySQL: ' . mysql_error() );


//Select the databse
//If a it doesn't exist then create one
$dbs = mysql_select_db (DB_NAME);


//Select the table
//If it doesn't exist then create one
$table_name = 'brisk_downloads_url'; //Name of the table on the database that will store the information
$query = mysql_query("SELECT * FROM `$table_name`"); //Query the database for a duplicate visible name

$upload_dir = "/usr/local/apache2/[URL unfurl="true"]wwwroot/briskfire.com/downloads";[/URL] //Directory name (With path if there is one ie. /one/more/dir/uploads)(path is relative)

//Upload file processer
$dup_filename = FALSE;
$dup_vis_name = FALSE;
$upload_trouble = $_POST['new_vis_name']; //This is what the user entered as a visible file name

//Test for form submission
if($_POST['submit']) {

     //Test for file
     if($_FILES['file']['tmp_name']) { // If a file has been selected for uploading
          if(!is_uploaded_file($_FILES['file']['tmp_name'])) { //If the upload was successful     
               $message .= '<p>Failure. There was a problem uploading the file.</p>';
          }
     } else {
          $message .= '<p>Failure. No file was selected to upload.</p>';
     }
     
     //Test for visible name
     if($_POST['new_vis_name']) {
          $query = mysql_query("SELECT * FROM `brisk_downloads_url`"); //Query the database for a duplicate visible name
          while($result = mysql_fetch_array($query)) {
               if($_POST['new_vis_name'] == $result['name']) {
                   $dup_vis_name = TRUE; // There is a duplicate visible name
               }
          }
          if ($dup_vis_name) {
               $message .= '<p>Failure. The "Visible Name" is already in use. 
               Please write a new name and try again.</p>';
          }
     } else {
          $message .= '<p>Failure. You forgot to enter a "Visible Name."</p>';
     }
     
     //Test for filename
     if ($handle = opendir($upload_dir)) { //Open the upload directory
          while (false !== ($file = readdir($handle))) { //Correct way to list all files in a directory
               if($_FILES['file']['name'] == $file) { //Check for duplicate file names
                    $dup_filename = TRUE; // There is a duplicate filename
               }
          }
          if ($dup_filename) {
               $message .= '<p>Failure. The file name is already in use 
               (not the "Visible Name"), please rename the file and try again.</p>';
          }
     }
     
     if($_FILES['file']['tmp_name'] && $_POST['new_vis_name'] && !$dup_vis_name && !$dup_filename) {
          $test = move_uploaded_file($_FILES['file']['tmp_name'], $upload_dir . '/' . $_FILES['file']['name']);
          if(!$test) {echo 1;}
          mysql_query("INSERT INTO `$table_name` ( `dl_url_id` , `dl_section` , `dl_url` , `linkname` , `title`, `description`, `clicks` ) 
          VALUES ('', '$sectionid', '" . $_FILES['file']['name'] . "', '" . $_POST['linkname'] . "', '" . $_POST['new_vis_name'] . "', '" . $_POST['description'] . "', '' );");
          $message .= '<p><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif">The download was added to the database.<br> Add a new download below if you wish.</font></p>';
          $upload_trouble = NULL;
     }

}
?>
          <form name="main" method="post" enctype="multipart/form-data" action="">
               
  <br>
          <table cellpadding="5" border="0">
                      <tr>
						 <? echo $message ?>
                    </tr>

                    <tr>
						 
              <td><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif">Title:</font></td>
                         <td><input name="new_vis_name" value="" size="40"></td>
                    </tr>
                    <tr>
                         
              <td><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif"> 
                Download file name:</font></td>
                         <td><input type="file" name="file" size="26"></td>
                    </tr>
                    <tr>
					     <td><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif">Description:</font></td>
						 <td><input name="description" value="" size="40"></td>
					</tr>
					<tr>
					     
              <td><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif">Link 
                name</font></td>
						 <td><input name="linkname" value="" size="40"></td>
				    </tr>
					<tr>	
                         <td colspan="2" align="center"><input type="submit" name="submit" value="Add Download"></td>
                    </tr>
               </table>
               
          <p>&nbsp; </p>
  </form>
        </p>

        <p><font color="#4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="index.php?page=admin/login/hom3d7r/content/downloads/dl_add_select">Return 
          to Add Download Section menu</a></font></p>
        <p>&nbsp;</p></div></td>
  </tr>
</table>

Can anyone tell me is there a default file upload limit that can be specified within the apache conf file? How do i remove this limit and make it so i can upload files as big as i want? The limit size is not specified within the script above, does this matter or is the limit specified else where within apache?

Thanks for the help

Jim

 
Hi, please attatch your error-code.
I have uploaded over 800kb without trouble, but with so little info, it's impossible to guess what your problem is.

very few people will bother testing your code for you, for free, sorry.

Olav Alexander Mjelde
Admin & Webmaster
 
sorry...

i get this error message wen trying to upload big files:

"There was an error uploading the file, please try again!"

Is there not a piece of code i can use to try and troubleshoot the error?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top