Page 1 of 1

uploading woes

Posted: Tue Jun 03, 2003 11:35 pm
by matthiasone
I am trying to write a simple uploading script from a form.

Here is the form code

Code: Select all

function gallery_newpic()
{
  $sdate = date('Y-m-d', strtotime('now'));
  $edate = date('Y-m-d', strtotime('12 weeks from '.$sdate));
  $query = "SELECT picnum FROM gallery WHERE expdate <= '".$sdate."'";
  $result = query_db($query);
  $num_rows = mysql_num_rows($result);
  if ($num_rows > 0)
  &#123;
    $pc = mysql_fetch_array($result);
	$action_url = "gallery_fns.php?page=upd";
  &#125;
  else	 
    $action_url = "gallery_fns.php?page=add1";
?>

  <table border="0" cellpadding="0" cellspacing="0">
    <tr>	
	  <td colspan="2"><font size="5"><b>Picture Gallery Entry</b></font></td>
	</tr>
	<tr>	
	  <td><font size="2">Choose File: </font></td>
	  <td><form method="post" action="gallery_fns.php?page=add1" ENCTYPE="multipart/form-data"><INPUT TYPE="file" NAME="pic"></td>
	</tr>
	<TR>
	  <TD COLSPAN="2"><INPUT VALUE="Submit" TYPE="submit"></form></TD>
	</TR> 
</TABLE>
</form> 
<?
&#125;
Here is the uploading script

Code: Select all

function gallery_upload1($form_vars, $mode, $id="")
&#123;
 	$uploaddir = '/usr/home/christschurch/gallery';
    echo 'fn='.$_FILES&#1111;'userfile']&#1111;'name'].'<br>';
    echo 'fn1='.$form_vars&#1111;'userfile']&#1111;'name'].'<br>';
  	echo 'h='.$HTTP_POST_FILES&#1111;'userfile']&#1111;'name'].'<br>';
  	echo 'h1='.$HTTP_POST_FILES&#1111;'userfile']&#1111;'tmp_name'].'<br>';
	if (move_uploaded_file($_FILES&#1111;'userfile']&#1111;'tmp_name'], $uploaddir . $_FILES&#1111;'userfile']&#1111;'name'])) 
	&#123;
      print "File is valid, and was successfully uploaded.  Here's some more debugging info:\n";
      print_r($_FILES);
	&#125;
  	$sdate = date('Y-m-d', strtotime('now'));
  	$edate = date('Y-m-d', strtotime('+3 months'));
    if ($mode == "u")
    &#123;
	  $query = "UPDATE gallery SET ".
               "entrydate = '".$sdate."', ".
               "expdate = '".$edate."', ".
		       "image = '".$_FILES&#1111;'userfile']&#1111;'name']."' ".
  		       "WHERE picnum = ". $form_vars&#1111;'pid'];
  &#125;
  if ($mode == "n")
  &#123;
    $query = "INSERT INTO gallery VALUES(".
             "NULL, ".
             "'".$sdate."', ".
		     "'".$edate."', ".
		     "'".$_FILES&#1111;'userfile']&#1111;'name']."') ";
  &#125;
  echo $query.'<br>';
  $result = query_db($query);
&#125;
Here is what the echos give me

Code: Select all

fn=
fn1=
h=
h1=
INSERT INTO gallery VALUES(NULL, '2003-06-03', '2003-09-03', '')
Any ideas what I am missing???????

Posted: Wed Jun 04, 2003 1:42 am
by detrox
1. you have a incorrect order of tags </form> and </table>.
2. the name of the file object is "pic" why you use $_FILE["userfile"],
you should use $_FILE["pic"]