[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP - A file upload renders the POST array to NULL

Posted on 2011-10-31
8
Medium Priority
?
306 Views
Last Modified: 2012-05-12
I have a form which has an input file field named link.  When I use the file upload field in a form I have, it causes the POST to come up null.  To view the contents of the POST. I used the code:
$query_string = "";
	if ($_POST) {
	  $kv = array();
	  foreach ($_POST as $key => $value) {
		$kv[] = "$key=$value";
	  }
	}

Open in new window

If I leave the code for the file upload in the page and don't use it, then everything comes up fine.  I tried changing the name of the file field with no change.  I also tried to change the input type from file to text with the same name while typing some text - It works fine.  It seems the issue is being cause directly by the use of an upload.  I do have enctype="multipart/form-data" on my form.

Any insight is appreciated, thank you.
0
Comment
Question by:andrewaiello
  • 5
  • 3
8 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 37058589
Please post the form.

How big is the file you are uploading?
0
 
LVL 1

Author Comment

by:andrewaiello
ID: 37058955
I've tried a 9mb pdf and a 46kb pdf, they both don't work.  This page is kinda weird, it a file upload tool, it's purpose is to allow the user to upload an image, text (using ckeditor), a pdf, and an order number to a database for use with a gallery kind of purpose.  The form giving the problem is as follows:

<form action="admin_minislide.php?section=MiniSlide&action=viewing" method="POST" name="edit" enctype="multipart/form-data">
                                <table border="2px" align="center" bordercolor="#000000" width="550">
                                    <tr>
                                        <td width="27%" align="right">Image:</td>
                                        <td width="73%">
                                        	
                                            <input type="file" name="image" id="image"/>
                                            Erase:
                                            <select name="editErase" id="editErase">
                                            	<option value="NULL" selected="selected">Choose One...</option>
                                                <option value="No">No</option>
                                                <option value="Yes">Yes</option>	
                                        	</select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td height="128">
                                        </td>
                                        <td>
                                        
                                        <?php if($_GET['action'] == "editing"){?>
                                            <img src="<?php echo $row_rsEditSelect['image']; ?>" height="200px" width="200px"  />
                                        	<?php } ?>
										
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right">Text:</td>
                                        <td>
                 <textarea id="text" name="text"><?php if($_GET['action'] == "editing"){ echo $row_rsEditSelect['text']; } ?></textarea>
											 <?php
                                                include_once '../ckeditorPHP/ckeditor.php' ;
                                                require_once '../ckfinderPHP/ckfinder.php' ;
                                                $initialValue = 'Hey' ;
                                                $ckeditor = new CKEditor( ) ;
                                                $ckeditor->basePath = '../ckeditorPHP/' ;
                                                CKFinder::SetupCKEditor( $ckeditor,'../ckfinderPHP/' ) ;
                                                $ckeditor->replace('text');
                                             ?>
                                        </td>
                                    </tr>
                                    <tr>
                                    	<td align="right">
                                        	PDF Upload:
                                        </td>
                                        <td>
                                        	<input type="file" name="link" id="link" />
                                            <?php if($_GET['action'] == "editing"){?>
                                            Erase: <select name="linkErase" id="linkErase">
                                            		<option selected="selected">Choose On</option>
                                                    <option value="No">No</option>
                                                    <option value="Yes">Yes</option>
                                            	</select>
                                                <br />
                                                <a href="<?php echo $row_rsEditSelect['link']; ?>">Current pdf</a>
                                            
                                            <?php } ?>
                                            
                                      	</td>
                                    </tr>
                                    <tr>
                                        <td align="right">Order Number:</td>
                                        <td>
                                        	<?php if($_GET['action'] == "editing"){ ?>
                                            <input name="orderNum" type="text" id="orderNum" size="50" maxlength="3" value="<?php echo $row_rsEditSelect['orderNum']; ?>"/>
											<?php }else{ ?>
                                             <input name="orderNum" type="text" id="orderNum" size="50" maxlength="3" value=""/>
                                            <?php }  ?>
                                            
                                            
                                        </td>
                                    </tr>
                                    <tr>
                                   	  <td>
										<?php if($_GET['action'] == "editing"){ ?>
                                        <input type="hidden" name="editId" id="editId" value="<?php echo $row_rsEditSelect['record_id']; ?>" />
                                        <?php }else{ ?>
                                         <input type="hidden" name="editId" id="editId" value="" />
                                        <?php }  ?>
                                        
                                      	<input type="hidden" name="section" id="section" value="<?php echo $_GET['section']; ?>" />
                                      </td>
                                        <td>
                                        	<?php if($_GET['action'] == "viewing"){?>
                                                
                                                <input type="submit" name="addSubmit" id="addSubmit" value="Submit"/>
                                        	<?php } ?>
                                            <?php if($_GET['action'] == "editing"){?>
                                            	
                                                <input type="submit" name="editSubmit" id="editSubmit" value="Edit"/>
                                        	<?php } ?>
                                        </td>
                                    </tr>
                                </table>
                                
</form>

Open in new window

0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 37059607
Stripped of the extraneous stuff, here is the HTML form.   The only thing that jumps out at me is the lack of the MAX_FILE_SIZE directive.  See if any of these links get your attention.
http://php.net/manual/en/ini.core.php#ini.upload-max-filesize
http://php.net/manual/en/ini.core.php#ini.post-max-size
http://php.net/manual/en/info.configuration.php#ini.max-input-time

<?php // RAY_temp_andrew.php
error_reporting(E_ALL);
?>
<form action="http://laprbass.com/RAY_echo_chamber.php?section=MiniSlide&action=viewing" method="POST" name="edit" enctype="multipart/form-data">
<input type="file" name="image" id="image"/>
<select name="editErase" id="editErase">
<option value="NULL" selected="selected">Choose One...</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
<textarea id="text" name="text"></textarea>
<input type="file" name="link" id="link" />
<select name="linkErase" id="linkErase">
<option selected="selected">Choose On</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
<input name="orderNum" type="text" id="orderNum" size="50" maxlength="3" value=""/>
<input type="hidden" name="editId" id="editId" value="" />
<input type="hidden" name="section" id="section" value="Foo" />
<input type="submit" name="editSubmit" id="editSubmit" value="Edit"/>
</form>

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 37059612
Here is the echo chamber script.  When I ran this (with two admittedly small files for upload) I got a successful result.
<?php // RAY_echo_chamber.php
error_reporting(E_ALL);

// OPEN AN OUTPUT BUFFER
ob_start();

// SHOW THE EXTERNAL SUPERGLOBALS
echo "<pre>";
echo PHP_EOL . "GET ";     var_dump($_GET);
echo PHP_EOL . "POST ";    var_dump($_POST);
echo PHP_EOL . "FILES ";   var_dump($_FILES);
echo PHP_EOL . "COOKIE ";  var_dump($_COOKIE);

// CAPTURE THE BUFFER
$vardump = ob_get_clean();

// SHOW THE RESULTS
echo $vardump;

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 37059621
You can test yourself if you want at this URL
http://www.laprbass.com/RAY_temp_andrew.php
0
 
LVL 1

Author Comment

by:andrewaiello
ID: 37060365
I'm sorry, I saw your reply when I left work, but haven't been able to get on since.  I don't have the files with me at home, but I'm looking at the links you provided and will try some of it out tomorrow morning.

Thank you again
0
 
LVL 1

Author Closing Comment

by:andrewaiello
ID: 37062763
I set the ini commands you gave me to like 20mb + or - because some have to be higher then others along with

http://www.php.net/manual/en/ini.core.php#ini.memory-limit

and it worked, 1st try.  After that I commented them out 1 at a time to see which one(s) did the trick and I ended up commenting them all out.  I'm getting the notion that ini variables are set on a per session basis, because I just haven't closed my browser yet.  I'm going to test that out right now, but I wanted to post that it worked, thank you.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 37062881
That's great news. Thanks for the points! ~Ray
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question