[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

upload images to database

i just added another part of the form for the user to add images to the database to be reflected somewhere in the site at a later time. I made this code and it all works just fine except for the image part..all the other categories went to the database but for the imagename, imagesize, image, imagetype, or imagecontent. What could be wrong with my code?
<?php
$item = $_POST['item'];
$category = $_POST['category'];
$Qty_onHand = $_POST['Qty_onHand'];
$price = $_POST['price'];
$description = $_POST['description'];
$Qty_onHand = $_POST['Qty_onHand'];
if(isset($_POST['upload']) && $_FILES['userfile']['size'] >  0)
{
$fileName = $_FILES['userfile']['imagename'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['imagesize'];
$fileType = $_FILES['userfile']['imagetype'];

$fp      = fopen($tmpName, 'r');
$imagecontent = fread($fp, filesize($tmpName));
$imagecontent = addslashes($imagecontent);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}}
// Filter Function -------------------------------------------------------------------
function filterFunction ($var) { 
    $var = nl2br(htmlspecialchars($var));
    $var = eregi_replace("'", "&#39;", $var);
    $var = eregi_replace("`", "&#39;", $var);
    return $var; 
} 
$item = filterFunction($item);
$category = filterFunction($category);
$Qty_onHand = filterFunction($Qty_onHand);
// End Filter Function --------------------------------------------------------------
include_once "../Scripts/connect_to_mysql.php";
// Add the info into the database table
$query = mysqli_query($myConnection, "INSERT INTO items (item, category, Qty_onHand, price, description, imagename, imagesize, imagetype, imagecontent) 
        VALUES('$item','$category','$Qty_onHand','$price', '$description', '$fileName',  '$fileSize', '$fileType', '$imagecontent')") or die (mysqli_error($myConnection));

echo 'Operation Completed Successfully! <br /><br /><a href="items.php">Click Here</a>';
exit();
?>

Open in new window

0
chefkeifer
Asked:
chefkeifer
  • 9
  • 8
  • 5
1 Solution
 
hieloCommented:
>>$fileName = $_FILES['userfile']['imagename'];
where did imagename come from?
>>$fileSize = $_FILES['userfile']['imagesize'];
where did imagesize come from?

Don't be making stuff up. Read the manual.
http://us.php.net/manual/en/features.file-upload.post-method.php
:)
0
 
chefkeiferAuthor Commented:
i read the manual earlier and also found and example and implemented i changed the name to imagename and didnt realize that was what was reading the file...i have changed that back and i still get the same scenerio..

this the form part that have..i might be missing something
<tr>
                            <td width="246">Item Image:</td>
                            <td width="39"><input type="hidden" name="MAX_FILE_SIZE" value="2000000" />                              
                                <input name="userfile" type="file" id="userfile" />
                            </tr>
                        <tr>
                          <td>&nbsp;</td>
                          <td colspan="2"><input type="submit" name="button" id="button" value="Create this page now" />
                            </td>
                          </tr>

or course there are other parts of the form but that is the image part and the submit..

i am assuming i am not classifying something in the form part
<?php
$item = $_POST['item'];
$category = $_POST['category'];
$Qty_onHand = $_POST['Qty_onHand'];
$price = $_POST['price'];
$description = $_POST['description'];
$Qty_onHand = $_POST['Qty_onHand'];

if(isset($_POST['upload']) && $_FILES['userfile']['size'] >  0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}}
// Filter Function -------------------------------------------------------------------
function filterFunction ($var) { 
    $var = nl2br(htmlspecialchars($var));
    $var = eregi_replace("'", "&#39;", $var);
    $var = eregi_replace("`", "&#39;", $var);
    return $var; 
} 
$item = filterFunction($item);
$category = filterFunction($category);
$Qty_onHand = filterFunction($Qty_onHand);
// End Filter Function --------------------------------------------------------------
include_once "../Scripts/connect_to_mysql.php";
// Add the info into the database table
$query = mysqli_query($myConnection, "INSERT INTO items (item, category, Qty_onHand, price, description, imagename, imagesize, imagetype, imagecontent) 
        VALUES('$item','$category','$Qty_onHand','$price', '$description', '$fileName',  '$fileSize', '$fileType', '$content')") or die (mysqli_error($myConnection));

echo 'Operation Completed Successfully! <br /><br /><a href="items.php">Click Here</a>';
exit();
?>

Open in new window

0
 
hieloCommented:
what datatype if your imagecontent field in your db? Also, try;
if(isset($_FILES['userfile']) && $_FILES['userfile']['size'] >  0)
{
	$fileName = $_FILES['userfile']['name'];
	$tmpName  = $_FILES['userfile']['tmp_name'];
	$fileSize = $_FILES['userfile']['size'];
	$fileType = $_FILES['userfile']['type'];

	$fp      = fopen($tmpName, 'r');
	$content = fread($fp, filesize($tmpName));
	//$content = addslashes($content);
	fclose($fp);

	if(!get_magic_quotes_gpc())
	{
		$content = addslashes($content);
		$fileName = addslashes($fileName);
	}
}

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Ray PaseurCommented:
Strongly suggest that you NOT put images into the data base.  Instead keep them in the file system of your server and keep the URL in the data base.  Lots of reasons for this, but performance, backup, etc., are high among them.

I know you don't like to read, but this (file uploads) is a rather advanced topic with implications for security.  So I urge you to make an exception and start your reading here:
http://us.php.net/manual/en/features.file-upload.php

Here is a teaching example of how to upload files to the server.  Store the file names in the data base and you're home free!

Happy New Year to all, ~Ray
<?php // RAY_upload_example.php
error_reporting(E_ALL);


// MANUAL REFERENCE PAGES
// http://docs.php.net/manual/en/features.file-upload.php
// http://docs.php.net/manual/en/features.file-upload.common-pitfalls.php
// http://docs.php.net/manual/en/function.move-uploaded-file.php
// http://docs.php.net/manual/en/function.getimagesize.php


// ESTABLISH THE NAME OF THE 'uploads' DIRECTORY
$uploads = 'uploads';

// ESTABLISH THE BIGGEST FILE SIZE WE CAN ACCEPT
$max_file_size = '8192000';  // EIGHT MEGABYTE LIMIT ON UPLOADS

// ESTABLISH THE KINDS OF FILE EXTENSIONS WE CAN ACCEPT
$file_exts = array('jpg', 'gif', 'png', 'txt', 'pdf');

// ESTABLISH THE MAXIMUM NUMBER OF FILES WE CAN UPLOAD
$nf = 3;



// THIS IS A LIST OF THE POSSIBLE ERRORS THAT CAN BE REPORTED IN $_FILES[]["error"]
$errors    = array(
    0 => "Success!",
    1 => "The uploaded file exceeds the upload_max_filesize directive in php.ini",
    2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form",
    3 => "The uploaded file was only partially uploaded",
    4 => "No file was uploaded",
    6 => "Missing a temporary folder",
    7 => "Cannot write file to disk"
);




// IF THERE IS NOTHING IN $_POST, PUT UP THE FORM FOR INPUT
if (empty($_POST))
{
    ?>
    <h2>Upload <?php echo $nf; ?> file(s)</h2>

    <!--
        SOME THINGS TO NOTE ABOUT THIS FORM...
        NOTE THE CHOICE OF ENCTYPE IN THE HTML FORM STATEMENT
        MAX_FILE_SIZE MUST PRECEDE THE FILE INPUT FIELD
        INPUT NAME= IN TYPE=FILE DETERMINES THE NAME YOU FIND IN $_FILES ARRAY
    -->

    <form name="UploadForm" enctype="multipart/form-data" action="<?=$_SERVER["REQUEST_URI"]?>" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="<?=$max_file_size?>" />
    <p>
    Find the file(s) you want to upload and click the "Upload" button below.
    </p>

    <?php for ($n = 0; $n < $nf; $n++)
        {
            echo "<input name=\"userfile$n\" type=\"file\" size=\"80\" /><br/>\n";
        }
    ?>
    <br/>Check this box <input autocomplete="off" type="checkbox" name="overwrite" /> to <b>overwrite</b> existing files.
    <input type="submit" name="_submit" value="Upload" />
    </form>
    <?php
    die();
}
// END OF THE FORM SCRIPT




else // WE HAVE GOT SOMETHING IN $_POST - RUN THE ACTION SCRIPT
{

// THERE IS POST DATA - PROCESS IT
    echo "<h2>Results: File Upload</h2>\n";

// ACTIVATE THIS TO SEE WHAT IS COMING THROUGH
//    echo "<pre>"; var_dump($_FILES); var_dump($_POST); echo "</pre>\n";

// ITERATE OVER THE CONTENTS OF $_FILES
    foreach ($_FILES as $my_uploaded_file)
    {

// SKIP OVER EMPTY SPOTS - NOTHING UPLOADED
        $error_code    = $my_uploaded_file["error"];
        if ($error_code == 4) continue;

// SYNTHESIZE THE NEW FILE NAME
        $f_type    = trim(strtolower(end    (explode( '.', basename($my_uploaded_file['name'] )))));
        $f_name    = trim(strtolower(current(explode( '.', basename($my_uploaded_file['name'] )))));
        $my_new_file = getcwd() . '/' . $uploads . '/' . $f_name .'.'. $f_type;
        $my_file     = $uploads . '/' . $f_name .'.'. $f_type;

// OPTIONAL TEST FOR ALLOWABLE EXTENSIONS
        if (!in_array($f_type, $file_exts)) die("Sorry, $f_type files not allowed");

// IF THERE ARE ERRORS
        if ($error_code != 0)
        {
            $error_message = $errors[$error_code];
            die("Sorry, Upload Error Code: $error_code: $error_message");
        }

// GET THE FILE SIZE
        $file_size    = number_format($my_uploaded_file["size"]);

// MOVE THE FILE INTO THE DIRECTORY
// IF THE FILE IS NEW
        if (!file_exists($my_new_file))
        {
            if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
            {
                $upload_success = 1;
            }
            else
            {
                $upload_success = -1;
            }

// IF THE FILE ALREADY EXISTS
        }
        else
        {
            echo "<br/><b><i>$my_file</i></b> already exists.\n";

// SHOULD WE OVERWRITE THE FILE? IF NOT
            if (empty($_POST["overwrite"]))
            {
                $upload_success = 0;

// IF WE SHOULD OVERWRITE THE FILE, TRY TO MAKE A BACKUP
            }
            else
            {
                $now    = date('Y-m-d');
                $my_bak = $my_new_file . '.' . $now . '.bak';
                if (!copy($my_new_file, $my_bak))
                {
                    echo "<br/><b>Attempted Backup Failed!</b>\n";
                }
                if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
                {
                    $upload_success = 2;
                }
                else
                {
                    $upload_success = -1;
                }
            }
        }

// REPORT OUR SUCCESS OR FAILURE
        if ($upload_success == 2) { echo "<br/>It has been overwritten.\n"; }
        if ($upload_success == 1) { echo "<br/><b><i>$my_file</i></b> has been saved.\n"; }
        if ($upload_success == 0) { echo "<br/><b>It was NOT overwritten.</b>\n"; }
        if ($upload_success < 0)  { echo "<br/><b>ERROR <i>$my_file</i> NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND</b>\n"; }
        if ($upload_success > 0)
        {
            echo "$file_size bytes uploaded.\n";
            if (!chmod ($my_new_file, 0755))
            {
                echo "<br/>chmod(0755) FAILED: fileperms() = ";
                echo substr(sprintf('%o', fileperms($my_new_file)), -4);
            }
            echo "<br/><a href=\"$my_file\">See the file $my_file</a>\n";
        }
// END ITERATOR
    }
}

Open in new window

0
 
chefkeiferAuthor Commented:
i am not against putting the images on the server..i actually started that way and then i READ something...it most have been bogus...that is was easier to just put them in the database.. and then refer to them. to be honest with you i would rather just put them in a directory and then pull them out later..it could easier to organize that way....

on a personal note..Ray its not that I do not like to read...i have a serious comprehension disability. No lie, you could give me a Dr. Suess book and I would still have to read it 10 times to understand what i just read. I have had to adapt over many years to be a more hands on person...you know the type..take something that is given to you..take it part then you can put it back together.  I am not trying to be difficult here..i am doing my research and then trying to implement it...when i have difficulties i come here. I do not just post something and then hope someone does it for me.

I really do appreciate your help and your teaching tools..i have READ them and I am also trying to use those tools in the the things that i am creating. It is very much appreciated...



0
 
Ray PaseurCommented:
@chefkeifer: I know you're not trying to be difficult, and I certainly understand that it takes using examples to learn from them - at least it does for me.  Still there are some things that are so complicated that we just do not have time to make up examples for you - many of those examples already exist in the PHP online manual.  It is not that we are lazy, it is just that there is not enough time to give you a timely response - without copying the PHP manual, and that is not helpful to anyone.  If you look at an example in the PHP man page and do not understand it, by all means post a question - we are glad to try to explain or clarify their examples.

And definitely use the file system for the images.  Then you can also use the HTML <img> tag when you want to present the images to clients.

Cheers, ~Ray
0
 
chefkeiferAuthor Commented:
right back at ya Ray..Cheers!! time to go ring in the new year and then tomorrow try to tweak this site that is way...way...over my head...


Hielo...thanks to you as well
0
 
hieloCommented:
>>Strongly suggest that you NOT put images into the data base
I second that motion. Actually I started writing that at the end of my previous post, but had to leave, so I just deleted that part and posted what I had.

>>Hielo...thanks to you as well
Glad to help.

Happy New Year to both of you!

Regards,
Hielo
0
 
chefkeiferAuthor Commented:
okey dokey..i came up with this...it seems to work fine except for the image itself..

its making the directory on the server...but the database is not INSERTing the filename nor is the actual image going to the server. I have used this script before but with flash and not from a html form.


<?php
$item = $_POST['item'];
$category = $_POST['category'];
$Qty_onHand = $_POST['Qty_onHand'];
$price = $_POST['price'];
$description = $_POST['description'];
$Qty_onHand = $_POST['Qty_onHand'];
$filename = $_POST['filename'];
$filename = $_FILES['userfile']['name'];        
$filetmpname = $_FILES['userfile']['tmp_name']; 
$fileType = $_FILES["userfile"]["type"];
$fileSizeMB = ($_FILES["userfile"]["size"] / 1024 / 1000);
//=============================================================

$file_dir= "../items/images/$item/";

if (!is_dir($file_dir)) {
        mkdir($file_dir);       
}
move_uploaded_file($_FILES['userfile']['tmp_name'], $file_dir.$filename);

// Filter Function -------------------------------------------------------------------
function filterFunction ($var) { 
    $var = nl2br(htmlspecialchars($var));
    $var = eregi_replace("'", "&#39;", $var);
    $var = eregi_replace("`", "&#39;", $var);
    return $var; 
} 
$item = filterFunction($item);
$category = filterFunction($category);
$Qty_onHand = filterFunction($Qty_onHand);
// End Filter Function --------------------------------------------------------------
include_once "../Scripts/connect_to_mysql.php";
// Add the info into the database table
$query = mysqli_query($myConnection, "INSERT INTO items (item, category, Qty_onHand, price, description, imagename) 
        VALUES('$item','$category','$Qty_onHand','$price', '$description', '$filename')") or die (mysqli_error($myConnection));

echo 'Operation Completed Successfully! <br /><br /><a href="items.php">Click Here</a>';
exit();
?>
===============================================
FORM:
<form id="form" name="form" method="post" action="item_new_parse.php" onsubmit="return validate_form ( );">
                        <tr>
                          <td width="15%" align="right">New Item:</td>
                          <td width="85%" colspan="2"><input name="item" type="text" id="item" size="75" maxlength="64" value="<?php echo $item; ?>" /></td>
                          </tr>
                        <tr>
                          <td align="right">Category:</td>
                          <td colspan="2"><input name="category" type="text" id="category" size="75" maxlength="64" value="<?php echo $category; ?>" /></td>
                          </tr>
                        <tr>
                          <td align="right">Quantity on Hand:</td>
                          <td colspan="2"><input name="Qty_onHand" type="text" id="Qty_onHand" size="75" maxlength="64" value="<?php echo $Qty_onHand; ?>" /></td>
                          </tr>
                        <tr>
                          <td align="right">Price:</td>
                          <td colspan="2"><input name="price" type="text" id="price" size="75" maxlength="64" value="<?php echo $price; ?>" /></td>
                          </tr>
                        <tr>
                          <td align="right" valign="top">Item Description:</td>
                          <td colspan="2"><textarea name="description" id="description" cols="50" rows="16"><?php echo $description; ?></textarea></td>
                          </tr>
                        <tr>
                            <td width="246">Item Image:</td>
                            <td width="39">                            
                                <input name="userfile" type="file" id="userfile" />
                            </tr>
                        <tr>
                          <td>&nbsp;</td>
                          <td colspan="2"><input type="submit" name="button" id="button" value="Create this page now" />
                            </td>
                          </tr>
                        </form>

Open in new window

0
 
hieloCommented:
>>its making the directory on the server.
Check the permissions:
<?php
error_reporting(E_ALL);
$item = $_POST['item'];
$category = $_POST['category'];
$Qty_onHand = $_POST['Qty_onHand'];//duplicate of line 7
$price = $_POST['price'];
$description = $_POST['description'];
$Qty_onHand = $_POST['Qty_onHand'];
$filename = $_POST['filename'];//duplicate of line 9
$filename = $_FILES['userfile']['name'];        
$filetmpname = $_FILES['userfile']['tmp_name']; 
$fileType = $_FILES["userfile"]["type"];

//$fileSizeMB = ($_FILES["userfile"]["size"] / 1024 / 1000);
$fileSizeMB = ((int)$_FILES["userfile"]["size"] / (1024*1024) );
//=============================================================

$file_dir= "../items/images/$item/";
echo "<br>file_dir is $file_dir";
if (!is_dir($file_dir)) {
        mkdir($file_dir,0755);//specify the permissions
}
move_uploaded_file($_FILES['userfile']['tmp_name'], $file_dir.$filename);
...

Open in new window

0
 
Ray PaseurCommented:
You may have more than one issue here.  Consider this line:

$filename = $_FILES['userfile']['name'];        

If you store only that in the data base, it may not be enough to find the file - IIRC that is like the "basename" of the file.  You might need to use getcwd() to get a fully qualified file name that you can use in the HTML <img> tag.

A good practice when debugging queries is to print the query out.  You can do something like this.  Important note - you should always create the query string in a variable and then pass the variable to the function.  It makes your programming and debugging much easier.
// Add the info into the database table

// CONSTRUCT THE QUERY
$sql = "INSERT INTO items (item,   category,   Qty_onHand,   price,    description,    imagename) 
                  VALUES('$item','$category','$Qty_onHand','$price', '$description', '$filename' )";

// VISUALIZE THE QUERY BEFORE RUNNING IT
var_dump($sql);

// RUN THE QUERY
$query = mysqli_query($myConnection, $sql) or die (mysqli_error($myConnection));

Open in new window

0
 
chefkeiferAuthor Commented:
ok i used the dump and got this

string(187) "INSERT INTO items (item, category, Qty_onHand, price, description, imagename) VALUES('phone','phones','500','2.50', 'sdkjf askdjh f;klasdj f;laksdj f', '' )" Operation Completed Successfully!

as far as just inputing the name..your saying i should put in the name, type, and size...I can add that for sure if that make of easier queries..at this point i am having issue geting just the name to INSERT in the database...

i noticed in the code above that it stops gathering the data after the description..could this be an issue again the in the form itself or is in the php coding...

hope all had a great New Years...

0
 
Ray PaseurCommented:
So it looks like this is the description column:
sdkjf askdjh f;klasdj f;laksdj f

And the imagename column appears to be empty.

The next step I would suggest, working backward to the data origins, is to use var_dump() to print out the $_FILES array.  Let's have a look at that next.
0
 
chefkeiferAuthor Commented:
i did this var_dump
var_dump($filename);

and got this
NULL Operation Completed Successfully!


of course it "Completed Successfully" thats how things work for me they work but not really:)
0
 
Ray PaseurCommented:
Let's try this:

use var_dump() to print out the $_FILES array.

var_dump($_FILES);

But BEFORE YOU DO THAT, go to the top of your script and put in this line:

error_reporting(E_ALL);

Then show us what you get.  Thanks, ~Ray
0
 
chefkeiferAuthor Commented:

ok with both i get this


array(0) { } Operation Completed Successfully!

0
 
Ray PaseurCommented:
Then you have no uploaded files.  Please post the form that is used to upload the files.  We need to see the form in its entirety from <form> to </form>

Please also refer to my post here: 12/31/09 04:24 PM, ID: 26156037
In that code snippet look at lines 40 - 70 where it shows what you have to have in the <form> to do a file upload.
0
 
chefkeiferAuthor Commented:
here is the form..i was thinking for some reason that would be an issue..there has been a soft point for me..i can make a flash form but not too familiar with html forms
<form id="form" name="form" method="post" action="item_new_parse.php" onsubmit="return validate_form ( );">
                        <tr>
                          <td width="15%" align="right">New Item:</td>
                          <td width="85%" colspan="2"><input name="item" type="text" id="item" size="75" maxlength="64" value="<?php echo $item; ?>" /></td>
                          </tr>
                        <tr>
                          <td align="right">Category:</td>
                          <td colspan="2"><input name="category" type="text" id="category" size="75" maxlength="64" value="<?php echo $category; ?>" /></td>
                          </tr>
                        <tr>
                          <td align="right">Quantity on Hand:</td>
                          <td colspan="2"><input name="Qty_onHand" type="text" id="Qty_onHand" size="75" maxlength="64" value="<?php echo $Qty_onHand; ?>" /></td>
                          </tr>
                        <tr>
                          <td align="right">Price:</td>
                          <td colspan="2"><input name="price" type="text" id="price" size="75" maxlength="64" value="<?php echo $price; ?>" /></td>
                          </tr>
                        <tr>
                          <td align="right" valign="top">Item Description:</td>
                          <td colspan="2"><textarea name="description" id="description" cols="50" rows="16"><?php echo $description; ?></textarea></td>
                          </tr>
                        <tr>
                            <td width="246">Item Image:</td>
                            <td width="39">                            
                                <input name="userfile" type="file" id="userfile" />
                            </tr>
                        <tr>
                          <td>&nbsp;</td>
                          <td colspan="2"><input type="submit" name="button" id="button" value="Create this page now" />
                            </td>
                          </tr>
                        </form>

Open in new window

0
 
Ray PaseurCommented:
Please see the code snippet.  Note the form declaration.  Note the max file size.  Check the comments in there.  You need to adapt these things into your form for it to work.  Have a go at that, then post your revised form and the var_dump() of $_FILES.  I will check back later this evening or tomorrow.  Best regards, ~Ray
<!--
        SOME THINGS TO NOTE ABOUT THIS FORM...
        NOTE THE CHOICE OF ENCTYPE IN THE HTML FORM STATEMENT
        MAX_FILE_SIZE MUST PRECEDE THE FILE INPUT FIELD
        INPUT NAME= IN TYPE=FILE DETERMINES THE NAME YOU FIND IN $_FILES ARRAY
    -->

    <form name="UploadForm" enctype="multipart/form-data" action="<?=$_SERVER["REQUEST_URI"]?>" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="<?=$max_file_size?>" />
    <p>
    Find the file(s) you want to upload and click the "Upload" button below.
    </p>

    <?php for ($n = 0; $n < $nf; $n++)
        {
            echo "<input name=\"userfile$n\" type=\"file\" size=\"80\" /><br/>\n";
        }
    ?>
    <br/>Check this box <input autocomplete="off" type="checkbox" name="overwrite" /> to <b>overwrite</b> existing files.
    <input type="submit" name="_submit" value="Upload" />
    </form>

Open in new window

0
 
chefkeiferAuthor Commented:
I got it to work thank you

i used the form code below
<form id="form" name="UploadForm" enctype="multipart/form-data" 
                       method="post" action="item_new_parse.php" onsubmit="return validate_form ( );">
                      <input type="hidden" name="MAX_FILE_SIZE" value="<?=$max_file_size?>" />
                        <tr>
                          <td width="15%" align="right">New Item:</td>
                          <td width="85%" colspan="2"><input name="item" type="text" id="item" size="75" maxlength="64" value="<?php echo $item; ?>" /></td>
                          </tr>
                        <tr>
                          <td align="right">Category:</td>
                          <td colspan="2"><input name="category" type="text" id="category" size="75" maxlength="64" value="<?php echo $category; ?>" /></td>
                          </tr>
                        <tr>
                          <td align="right">Quantity on Hand:</td>
                          <td colspan="2"><input name="Qty_onHand" type="text" id="Qty_onHand" size="75" maxlength="64" value="<?php echo $Qty_onHand; ?>" /></td>
                          </tr>
                        <tr>
                          <td align="right">Price:</td>
                          <td colspan="2"><input name="price" type="text" id="price" size="75" maxlength="64" value="<?php echo $price; ?>" /></td>
                          </tr>
                        <tr>
                          <td align="right" valign="top">Item Description:</td>
                          <td colspan="2"><textarea name="description" id="description" cols="50" rows="16"><?php echo $description; ?></textarea></td>
                          </tr>
                        <tr>
                            <td width="246">Item Image:</td>
                            <td width="39"><input name="userfile" type="file" id="userfile" />
                        </tr>
                        <tr>
                          <td>&nbsp;</td>
                          <?php for ($n = 0; $n < $nf; $n++)
								{
									echo "<input name=\"userfile$n\" type=\"file\" size=\"80\" /><br/>\n";
								}
							?>
                          <td colspan="2"><input type="submit" name="_submit" id="button" value="Upload" />
                            </td>
                          </tr>
                        </form>

Open in new window

0
 
Ray PaseurCommented:
Thanks for the points - glad we are making progress here, and best regards, ~Ray
0
 
hieloCommented:
>> var_dump($_FILES);
>> ok with both i get this array(0) { }
>> <form id="form" name="form" method="post" action="item_new_parse.php" onsubmit="return validate_form ( );">

Again, read the manual. On my first post I gave you a link where in example 1 it clearly has:
 enctype="multipart/form-data"

All the time you could have saved yourself if you would only read.

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 9
  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now