Page 1 of 1

server doesn't recognize file upload

Posted: Wed Nov 12, 2003 12:52 pm
by monkeynme
I'm using a file upload CLASS in my PHP to make file upload code easier. I've set up everything the way it should be (i think). But when I submit a file to be uploaded, I get an error message saying that the upload file field wasn't filled in. So i'm guessing that it doesn't recognize that a file has been selected for upload. Is there something missing in my code...or is it a php.ini issue where something hasn't been set up right?

Here is my code:

Code: Select all

<?php require_once('Connections/EagleMain.php'); ?>
<?php
include("class.upload_files.php");

$upload_class = new Upload_Files;
$upload_class->temp_file_name = trim($_FILES&#1111;'upload']&#1111;'resume_tmp']);
$upload_class->file_name = trim(strtolower($_FILES&#1111;'upload']&#1111;'resume']));
$upload_class->upload_dir = "resumes/";
$upload_class->upload_log_dir = "resumes/upload_logs/";
$upload_class->max_file_size = 5242880;
$upload_class->banned_array = array("");
$upload_class->ext_array = array(".doc",".txt");

$valid_ext = $upload_class->validate_extension();
$valid_size = $upload_class->validate_size();
$valid_user = $upload_class->validate_user();
$max_size = $upload_class->get_max_size();
$file_size = $upload_class->get_file_size();
$file_exists = $upload_class->existing_file();

	if (!$valid_ext) &#123;
		$result = "The file extension is invalid, please try again!";
	&#125;
	elseif (!$valid_size) &#123;
		$result = "The file size is invalid, please try again! The maximum file size is: $max_size and your file was: $file_size";
	&#125;
	elseif (!$valid_user) &#123;
		$result = "You have been banned from uploading to this server.";
	&#125;
	elseif ($file_exists) &#123;
		$result = "This file already exists on the server, please try again.";
	&#125; else &#123;
		$upload_file = $upload_class->upload_file_with_validation();
		if (!$upload_file) &#123;
			$result = "Your file could not be uploaded!";
		&#125; else &#123;
			$result = "Your file has been successfully uploaded to the server.";
		&#125;
	&#125;
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
&#123;
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) &#123;
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  &#125;
  return $theValue;
&#125;

$editFormAction = $HTTP_SERVER_VARS&#1111;'PHP_SELF'];
if (isset($HTTP_SERVER_VARS&#1111;'QUERY_STRING'])) &#123;
  $editFormAction .= "?" . $HTTP_SERVER_VARS&#1111;'QUERY_STRING'];
&#125;

if ((isset($HTTP_POST_VARS&#1111;"MM_insert"])) && ($HTTP_POST_VARS&#1111;"MM_insert"] == "form1")) &#123;
  $insertSQL = sprintf("INSERT INTO candidates (candFirstName, candLastName, candAddress, candCity, candState, candZip, candPhone, candFax, candEmail, jobType, coverLetter, candResume, jobID) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candFirstName'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candLastName'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candAddress'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candCity'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candState'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candZip'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candPhone'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candFax'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candEmail'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'jobType'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'coverLetter'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'candResume'], "text"),
                       GetSQLValueString($HTTP_POST_VARS&#1111;'jobID'], "int"));

  mysql_select_db($database_EagleMain, $EagleMain);
  $Result1 = mysql_query($insertSQL, $EagleMain) or die('<p>All fields must be completed!<br>'.
'Error: ' . mysql_error() . '</p>');

  $insertGoTo = "thankyou.htm";
  if (isset($HTTP_SERVER_VARS&#1111;'QUERY_STRING'])) &#123;
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $HTTP_SERVER_VARS&#1111;'QUERY_STRING'];
  &#125;
  header(sprintf("Location: %s", $insertGoTo));
&#125;

mysql_select_db($database_EagleMain, $EagleMain);
$query_submitResume = "SELECT * FROM candidates";
$submitResume = mysql_query($query_submitResume, $EagleMain) or die('<p>Error processing job candidates from the database!<br> />'.
'Error: ' . mysql_error() . '</p>');
$row_submitResume = mysql_fetch_assoc($submitResume);
$totalRows_submitResume = mysql_num_rows($submitResume);
?>
and my form has the following variables:

Code: Select all

<form method="post" name="form1" enctype="multipart/form-data" action="<?php echo $editFormAction; ?>">
with the upload field labelled as <input type="file" name="candResume">

Posted: Wed Nov 12, 2003 3:26 pm
by monkeynme
Ok, I made a little progress. Upon reviewing some more code on uploading files, I discovered that I got some variables backwards. Instead of:

Code: Select all

$upload_class->temp_file_name = trim($_FILES&#1111;'upload']&#1111;'resume_tmp']); 
$upload_class->file_name = trim(strtolower($_FILES&#1111;'upload']&#1111;'resume']));
it should be:

Code: Select all

$upload_class->temp_file_name = trim($_FILES&#1111;'candResume']&#1111;'tmp_name']);
$upload_class->file_name = trim(strtolower($_FILES&#1111;'candResume']&#1111;'name']));
But, I still get an error:

Code: Select all

Warning: filesize(): Stat failed for C:\WINNT\TEMP\php15.tmp (errno=2 - No such file or directory) in D:\Websites\Eagle Electronics Testing\class.upload_files.php on line 199

Warning: filesize(): Stat failed for C:\WINNT\TEMP\php15.tmp (errno=2 - No such file or directory) in D:\Websites\Eagle Electronics Testing\class.upload_files.php on line 257

Warning: filesize(): Stat failed for C:\WINNT\TEMP\php15.tmp (errno=2 - No such file or directory) in D:\Websites\Eagle Electronics Testing\class.upload_files.php on line 257

Warning: filesize(): Stat failed for C:\WINNT\TEMP\php15.tmp (errno=2 - No such file or directory) in D:\Websites\Eagle Electronics Testing\class.upload_files.php on line 199

All fields must be completed!
Error: Column 'candResume' cannot be null
Lines 199 and 257 in the CLASS file are:

Code: Select all

$size = filesize($temp_file_name);
Does this mean that the php.ini file was not set up a certain way?

Posted: Wed Nov 12, 2003 5:53 pm
by JAM
Hard to spot without the class and so on, but perhaps you can debug it abit more to get a different view of it...

Code: Select all

$upload_class->temp_file_name = trim($_FILES['candResume']['tmp_name']);
According to the err-msg, the canResume is null. So echo it out prior to using it in the class. If it shows correctly, echo it out inside the class.

Sticking...

Code: Select all

echo '<pre>';
print_r($_FILES);
echo '</pre>';
...in a strategic place might also help.
Give it some tries.