Jump to content

Stupid image file!!


BloodyMind

Recommended Posts

Hello there mates,

 

need your help about a little bit stupid problem but I have no clue what's happening

 

I've got an image file in my form, but it gives me a notice

 

Notice: Undefined index: proImage in xxx\bizlogic\projects.class.php on line 83

 

add-project.php:

<?php

require_once('../bizlogic/projects.class.php');
require_once('../bizlogic/verifier.class.php');
require_once('../bizlogic/gp.class.php');

$title = 'Catalyst Admin | Add Project';
$base_url = BASE_URL;
$addHeader = <<<EOHEAD
<!-- TinyMCE -->
<script type="text/javascript" src="$base_url/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
	// General options
	mode : "textareas",
	theme : "simple",
	plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

	// Theme options
	theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
	theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
	theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : true,

	// Example content CSS (should be your site CSS)
	content_css : "tinymce/css/content.css",

	// Drop lists for link/image/media/template dialogs
	template_external_list_url : "tinymce/lists/template_list.js",
	external_link_list_url : "tinymce/lists/link_list.js",
	external_image_list_url : "tinymce/lists/image_list.js",
	media_external_list_url : "tinymce/lists/media_list.js",

	// Replace values for the template plugin
	template_replace_values : {
		username : "catalyst",
		staffid : "9912344"
	}
});
</script>
EOHEAD;

$projects = new projects($db['host'],$db['username'],$db['password'],$db['name']);

$rows = $projects->getAllCategories();
if (!is_array($rows)) {
echo $rows;
die();
}

if ($_POST['submit'] == "Submit") {
$cat_id = $_POST['category'];
$title = $_POST['title'];
$name = $_POST['proName'];
$proDesc = $_POST['description'];
$owner = $_POST['owner'];
$typeOwork = $_POST['typeOwork'];
$city = $_POST['city'];
$state = $_POST['state'];
$value = $_POST['provalue'];
$attach = $_POST['attach'];

var_dump($_FILES);
$feedback = $projects->addProject($cat_id,$title,$name,$proDesc,$owner,$typeOwork,$attach, $city,$state,$value,'proImage');
if ($feedback !== TRUE) {
	echo $feedback;
	die();
}
}

include_once('../includes/header.inc.php');

include_once('../includes/sidebar.inc.php');
?>

    <h2>Add Project</h2>
    <br />
  <!-- Gets replaced with TinyMCE, remember HTML in a textarea should be encoded -->


<div>

<form method="post" action="<?php echo BASE_URL; ?>/admin/add-project.php">
  <table width="700" border="0" cellpadding="0" cellspacing="2" class="p">
        <tr>
          <td width="110" class="p"><strong>Category</strong></td>
        <?php 
        if ($feedback !== TRUE) {
        	echo $feedback;
        } ?>
              <td width="584"><label>
            <select name="category" id="category" style="p">
            <?php
            foreach ($rows as $row){
            	echo "<option value=" . $row['cat_id'] . ">" . $row['cat_title'] . "</option>\r\n";
            }
             ?>
            </select>
          </label></td>
        <tr>
          <td class="p"><strong>Title </strong></td>
          <td width="584"><span class="p">
            <input name="title" type="text" id="title" size="50" />
          </span></td>
        </tr>
        <tr>
          <td width="110" class="p"><strong><span class="p">Name</span></strong></td>
          <td><span class="p">
            <label>
              <input name="proName" type="text" id="textfield" size="50" />
            </label>
          </span></td>
        </tr>
        <tr>
          <td valign="top" class="p"><strong><span class="p">Description </span></strong></td>
          <td><span class="p">
            <textarea id="description" name="description" rows="15" cols="50" style="width: 80%">Description Goes here	</textarea>
             </span></td>
        </tr>
        <tr>
          <td class="p"><strong><span class="p">Owner</span></strong></td>
          <td><span class="p">
            <label>
              <input name="owner" type="text" id="textfield2" size="40" />
            </label>
          </span></td>
        </tr>
        <tr>
          <td class="p"><strong><span class="p">Type Of Work</span></strong></td>
          <td><span class="p">
            <label>
              <input name="typeOwork" type="text" id="textfield3" size="40" />
            </label>
          </span></td>
        </tr>
        <tr>
          <td class="p"><span class="p"><strong>City</strong></span></td>
          <td><span class="p">
            <input name="city" type="text" id="city" size="20" />
          </span></td>
        </tr>
        <tr>
          <td class="p"><span class="p"><strong>State</strong></span></td>
          <td><span class="p">
            <label>
              <input name="state" type="text" id="state" size="20" />
            </label>
          </span></td>
        </tr>
        <tr>
          <td class="p"><span class="p"><strong>Value</strong></span></td>
          <td><span class="p">
            <label>
              <input name="provalue" type="text" id="value" size="20" />
            </label>
          </span></td>
        </tr>
        <tr>
          <td class="p"><strong>Attachments</strong></td>
          <td><label>
            <input name="attach" type="checkbox" id="checkbox" value="1" />
          </label></td>
        </tr>
        <tr>
          <td class="p"><strong>Image</strong></td>
          <td><label>
            <input name="proImage" type="file" id="proImage" />
          </label></td>
        </tr>
      </table>
      	  <p> </p>
  <table width="700" border="0" cellpadding="1" cellspacing="0" class="p">
    <tr>
      <td width="105"><strong>Files:</strong></td>
      <td width="591"> </td>
      </tr>
    <tr>
      <td> </td>
      <td width="591"><label>
        <input name="file1" type="file" id="file1" size="30" />
        </label></td>
      </tr>
    <tr>
      <td> </td>
      <td width="591"><label>
        <input name="file2" type="file" id="file2" size="30" />
        </label></td>
      </tr>
    <tr>
      <td> </td>
      <td width="591"><label>
        <input name="file3" type="file" id="file3" size="30" />
        </label></td>
      </tr>
    <tr>
      <td> </td>
      <td width="591"><label>
        <input name="file4" type="file" id="file4" size="30" />
        </label></td>
      </tr>
    <tr>
      <td> </td>
      <td width="591"><label>
        <input name="file5" type="file" id="file5" size="30" />
        </label></td>
      </tr>
    </table>
    
  <p>
    <input type="submit" name="submit" value="Submit" />
    <input type="reset" name="reset" value="Reset" />
    </p>
    </form>
  <p><span class="redTxT" >*Note: please attach the project's image with width NOT more than 750 pixels wide.</span></p>

</div>

<p> </p>

<?php
require_once("../includes/footer.inc.php");
?>

 

 

Add Project Function:

<?php

public function addProject
(
$in_catId, 
$in_projectTitle,
$in_projectName,
$in_projectDescription, 
$in_owner,
$in_typeOwork,
$in_attachments=NULL, 
$in_city, 
$in_state, 
$in_value,
$in_imageFieldName
){
	try {
		if (empty($in_catId) or empty($in_projectTitle) or empty($in_projectDescription) or empty($in_city) or empty($in_state) or
		 empty($in_value)) {
			throw new Exception('Please fill in all mandatory fields.');
		}
		$projectTitle= Verifier::super_escape_string($in_projectTitle,$this->conn);

		$projectName = Verifier::validateName($in_projectName,'100','Project Name',$this->conn);

		$projectDescription = htmlentities($in_projectDescription);

		$owner = Verifier::validateName($in_owner,'100','Owner',$this->conn);

		$typeOwork = Verifier::validateName($in_typeOwork,'60','Type of Work',$this->conn);

		$city = Verifier::validateName($in_city,'60','City',$this->conn);

		$state = Verifier::validateName($in_state,'60','State',$this->conn);

		$value = Verifier::validateName($in_value,'60','Value',$this->conn);

		$image = null;
		if (is_uploaded_file($_FILES[$in_imageFieldName]['tmp_name'])) {
			$uploadedImage = Handles::uploadHandle('image',PROIMG_DIR,'Please upload a valid image file');
		}


		// if there is a project image, upload it
		if (isset($uploadedImage)) {
			$image = basename($uploadedImage);
			$image = urlencode($image);
			echo $image;
		}


		// if there is attachments upload the files
		if ($in_attachments !== NULL) {
			$feed = $this->uploadFiles();
			if ($feed!== TRUE) {
				throw new Exception($feed);
			}
		}

		$addsql = "INSERT INTO projects SET cat_id ='$in_catId',pro_title='$projectTitle',pro_name='$projectName' ,
		 pro_photo='$image', pro_desc='$projectDescription', owner='$owner', type_of_work = '$typeOwork', attachments='$in_attachments',
		  city='$city', state='$state', value='$value' ";
		$results = $this->conn->query($addsql);
		if ($results == FALSE) {
			throw new Exception('Database Error: Cannot add project');
		}



		return TRUE;

	}catch (Exception $e){
		return $e->getMessage();
	}	

}

?>

 

 

file handle here(Handles::uploadHandle()) :

 

/**
 * Verifies and uploads desired file
 *
 * @param string $in_inputeName input name in post
 * @param string $in_dir desired directory to upload to
 * @param string $err_str error msg to catch if error occured
 * @return string $fileupload path/filename.ext to the uploaded file
 */
static function uploadHandle($in_inputeName,$in_dir,$err_str){

	$blacklist = array(".php", ".phtml", ".php3", ".php4",".txt");
	foreach ($blacklist as $item) {
		if(preg_match("/$item\$/i", $_FILES[$in_inputeName]['name'])) {
			throw new Exception("We do not allow uploading PHP files\n");
		}
	}

	// UPLOAD_ERR_OK is file transfered successfully.
	if ($_FILES[$in_inputeName]['error'] !== UPLOAD_ERR_OK){
		throw new Exception($err_str);
	}
	$fileupload = $in_dir . basename($_FILES[$in_inputeName]['name']);
	if (!move_uploaded_file($_FILES[$in_inputeName]['tmp_name'],$fileupload)) {
		throw new Exception($err_str);
	}
	return $fileupload;

}
}

 

Constants:

<?php

define('DIR_PATH','C:/xampp/htdocs/catalyst');
define('PROIMG_DIR',DIR_PATH . '/uploads/projectImg/');
?>

 

by the way, I've tried to var_dump($_FILES) it returned and empty array  :(

Thanks in advance

Link to comment
Share on other sites

breifly:

<?php
// upload form
?>
<form method="post" action="<?php echo BASE_URL; ?>/admin/add-project.php">
<input name="proImage" type="file" id="proImage" />
</form>
<?php

// it gives me the notice here that the field name is undefined 
if (is_uploaded_file($_FILES['proImage']['tmp_name'])) {
            $uploadedImage = Handles::uploadHandle('proImage',PROIMG_DIR,'Please upload a valid image file');
}


 

Link to comment
Share on other sites

i'm just starting out with OOP, so take this in stride .. to my knowledge, you must have 'proImage' defined with the rest...no?

 

   $in_catId, 
   $in_projectTitle,
   $in_projectName,
   $in_projectDescription, 
   $in_owner,
   $in_typeOwork,
   $in_attachments=NULL, 
   $in_city, 
   $in_state, 
   $in_value,
   $in_imageFieldName
   //define proImage
   $in_proImage

Link to comment
Share on other sites

just look the code in the first post, to see the full picture

 

first I pass the input name to the add project function, then it is passed to the static function Handles::uploadHandle()

 

but I get an empty $_FILES array.... and that notice up there

 

thanks again

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.