3 Replies - 847 Views - Last Post: 02 March 2010 - 03:57 PM Rate Topic: -----

#1 morcomm  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 75
  • Joined: 28-March 08

Upload script - not working!

Posted 01 March 2010 - 02:55 AM

Hi, I have been working on a script that would upload a file, rename and add a entry into a DB to record it. It is not working and it is not throwing a error. I have looked over the sytax again and again and I am totally lost as to what is wrong

The form:
<form name="form" action="uploadscript_new.php" method="POST" enctype="multipart/form-data">
  <p>
          <label for="name">
            <input name="hiddenField" type="hidden" id="id" value="<?php echo $new_id; ?>" />
            <input name="hiddenField" type="hidden" id="hiddenField" value="execute" />
          Name of Link</label>
          <br />
<input type="text" name="name" id="name" />
        </p>
        <p>
          <label for="catorgory">Catorgory</label>
          <br />
          <span id="spryselect1">
          <select name="catorgory" id="catorgory">
            <option value="">Select</option>
            <?php
do {  
?>
            <option value="<?php echo $row_catorgory['catorgories']?>"><?php echo $row_catorgory['catorgories']?></option>
            <?php
} while ($row_catorgory = mysql_fetch_assoc($catorgory));
  $rows = mysql_num_rows($catorgory);
  if($rows > 0) {
      mysql_data_seek($catorgory, 0);
	  $row_catorgory = mysql_fetch_assoc($catorgory);
  }
?>
          </select>
        <span class="selectRequiredMsg">Please select an Catorgory.</span></span></p>
        <p>
          <label for="company">Company<br />
          </label>
          <span id="spryselect2">
          <select name="company" id="company">
            <option value="">Select</option>
            <?php
do {  
?>
            <option value="<?php echo $row_companies['short']?>"><?php echo $row_companies['company']?></option>
            <?php
} while ($row_companies = mysql_fetch_assoc($companies));
  $rows = mysql_num_rows($companies);
  if($rows > 0) {
      mysql_data_seek($companies, 0);
	  $row_companies = mysql_fetch_assoc($companies);
  }
?>
          </select>
        <span class="selectRequiredMsg">Please select an Company.</span></span></p>
        <p>
          <label for="expirydate">Expiry Date</label>
          <br />
<input type="text" name="expirydate" id="expirydate" class="datepicker" />
        </p>
        <p>
          <label for="file"></label>
          <input type="file" name="file" id="file" />
        </p>
        <p>
          <label for="button"></label>
          <input type="submit" name="button" id="button" value="Submit" />
        </p>
        <input type="hidden" name="MM_insert" value="form" />
</form>


The script
<?php 



require_once('Connections/main.php'); 

// Generate a random number
$random_number = rand(00000000, getrandmax()); 
$date_new = date ('d.m.Y');
$cat = $_REQUEST['catorgory'];
$new_id = $random_number .$date_new .$cat;

// Upload and Rename File
if (isset($_REQUEST['execute'])) {
 
$filename = $_FILES["file"]["name"];
$file_basename = substr($filename, 0, strripos($filename, '.')); // strip extention
$file_ext = substr($filename, strripos($filename, '.')); // strip name
$filesize = $_FILES["file"]["size"];
 
	if ($filesize < 2000000) {
		// rename file
		$newfilename = $new_id . $file_ext;
 
		if (file_exists("documents/" . $newfilename)) {
			// file already exists error
			$error = "There was a problem, please try again.";
		} else {
			move_uploaded_file($_FILES["file"]["tmp_name"], "documents/" . $newfilename);
					}
	} elseif (empty($file_basename)) {
		// file type error
		$error = "Please select a file to upload.";
	} else {
		// file selection error
		$error = "That file is too large.";
		unlink($_FILES["file"]["tmp_name"]);
	}
}


mysql_query("INSERT INTO tender_fileinfo (id, company, catorgory, discription, file, expiry_date) VALUES ('".$_REQUEST['id']."', '".$_REQUEST['company']."', '".$_REQUEST['catorgory']."', '".$_REQUEST['name']."', '".$_REQUEST['file']."','".$_REQUEST['expirydate']."')");



?>


Please help if you can, I am at a loss

Is This A Good Question/Topic? 0
  • +

Replies To: Upload script - not working!

#2 Auzzie  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 43
  • View blog
  • Posts: 573
  • Joined: 20-January 09

Re: Upload script - not working!

Posted 01 March 2010 - 03:22 AM

one thing you can do is echo out your variables one by one and see what ones are not being set properly and then it is just a process of elimination
Was This Post Helpful? 0
  • +
  • -

#3 morcomm  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 75
  • Joined: 28-March 08

Re: Upload script - not working!

Posted 01 March 2010 - 04:37 AM

View PostAuzzie, on 01 March 2010 - 02:22 AM, said:

one thing you can do is echo out your variables one by one and see what ones are not being set properly and then it is just a process of elimination



Ok, did that and they work until $filename then stop. To me it looks ok, not sure what is wrong
Was This Post Helpful? 0
  • +
  • -

#4 Auzzie  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 43
  • View blog
  • Posts: 573
  • Joined: 20-January 09

Re: Upload script - not working!

Posted 02 March 2010 - 03:57 PM

because you havent checked if the submit button has been pressed because you are using if (isset($_REQUEST['execute'])) { instead of if (isset($_REQUEST['submit'])) { so $filename doesn't actually get set
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1