?
Solved

UPLOAD issue

Posted on 2009-04-21
7
Medium Priority
?
273 Views
Last Modified: 2012-05-06
I created a php functionality that allows you to upload files to a directory.  It's been working great for the past 4 months until I tried uploading a .xps file (power point slide show).  How can I modify the code to accept .xps files?

Thanks.
<?php
 
 
	ini_set('error_reporting', E_ALL);
	ini_set('display_errors', "1");
	ini_set('display_startup_errors', "1");
 
	session_start();
	include('checkCred.php');
 
	$SECURITYUPLOAD = "D:/Websites/development Website/security/ADMIN/upload";
 
	if (isset($_POST["submit"]))
	{
		$MAX_FILE_SIZE = $_POST["MAX_FILE_SIZE"];
 
		if ($_FILES["uploadedfile"]["size"] < $MAX_FILE_SIZE)
		{
				if ($_FILES["uploadedfile"]["error"] > 0)
				{
					echo "<br />Return Code: " . $_FILES["uploadedfile"]["error"] . "<br />";
				}
				else
				{
					$result = "<span style=font-family:verdana;font-size:12px>Upload: " . $_FILES["uploadedfile"]["name"] . "</span><br />";
					$result .="<span style=font-family:verdana;font-size:12px>Type: " . $_FILES["uploadedfile"]["type"] . "</span><br />";
					$result .="<span style=font-family:verdana;font-size:12px>Size: " . ($_FILES["uploadedfile"]["size"] / 1024) . " Kb</span><br />";
					$result .="<span style=font-family:verdana;font-size:12px>Temp file: " . $_FILES["uploadedfile"]["tmp_name"] . "</span><br />";
 
					if (file_exists("$SECURITYUPLOAD/".$_FILES["uploadedfile"]["name"]))
					{
						echo $_FILES["uploadedfile"]["name"] . " already exists. ";
					}
					else
					{
						move_uploaded_file($_FILES["uploadedfile"]["tmp_name"], "$SECURITYUPLOAD/" . $_FILES["uploadedfile"]["name"]);
						//echo "Stored in: " . "upload/" . $_FILES["uploadedfile"]["name"];
					}
				}
		 }
		else
		{
			echo "File size is too big.  Limit is 19 MB<br>";
			echo "<span style=font-family:verdana>Size: ".($_FILES["uploadedfile"]["size"] / 1024) . " Kb</span><br />";
		}
	}
?>
 
<HTML>
 <HEAD>
 	<TITLE>UPLOAD Files</TITLE>
 	<meta http-equiv="refresh" content="60" />
 	<SCRIPT language="JavaScript">
	<!--
 
 	function confirmDelete()
	{
	    return confirm("Are you sure you wish to delete this entry?");
}
//-->
</SCRIPT>
 
 </HEAD>
 
 <BODY>
 
<br><br><br><br>
<form enctype="multipart/form-data" action="postFiles.php"  method="POST">
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 align="center" width="50%">
	<TR>
		<TD BGCOLOR="#CCCCCC">
			<TABLE CELLPADDING=3 CELLSPACING=1 BORDER=0 width="100%">
				<tr>
					<td colspan=2 style="background-color:#eeeeee;font-family:verdana;font-size:14px">Use this page to upload files to the Security page.</td>
				</tr>
				<TR>
				  <TD colspan="2" style="background-color:#eeeeee;font-family:verdana;font-weight:bold">Upload Files</TD>
				</TR>
				<TR>
				  <TD BGCOLOR="#FFFFFF">
					Choose a file to upload: <input name="uploadedfile" type="file" />
				  </TD>
				  <TD BGCOLOR="#FFFFFF">
					<input type="submit" value="Upload File" name="submit"/>
					<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
				  </TD>
				</TR>
			</TABLE>
		</TD>
	</TR>
</TABLE>
</form>
 
<table width="50%" align="center" cellpadding=0 cellspacing=0>
<tr><td bgColor="#cccccc">
	<table width="100%" border=0 align="center" cellpadding=3 cellspacing=1>
	<tr>
		<td style="background-color:#eeeeee;font-family:verdana;font-weight:bold">FILES</td>
		<td style="background-color:#eeeeee;font-family:verdana;font-weight:bold">DELETE</td>
	</tr>
	<?php
	$strPath = "upload";
 
	if ($handle = opendir($strPath))
	{
	//Alternate Row Colors codes
	$color1 = "#FFFFFF";
	$color2 = "#DDDDDD";
	$row_count = 0;
	$cnt=1;
 
		while (($file = readdir($handle)) !== false)
		{
			$row_color = ($row_count % 2) ? $color1 : $color2;  //Alternate Color
 
			if($file != "." && $file != "..")
			{
				echo '<tr style=background-color:'.$row_color.'><td><a href="'.$strPath.'\\'.$file.'" target="_blank">'.$file.'</a></td>';
				echo '<td><a href="delete.php?file='.$file.'" onclick="return confirmDelete();">delete</a></a></tr>';
			}
		$cnt++;
		$row_count++;  //Add 1 to the row count
		}
		closedir($handle);
	}
	?>
	</table>
</td></tr>
<tr>
	<td>
		<?php
			if (isset($result))
			{
				echo $result;
			}
		?>
	</td>
</tr>
</table>
</BODY>
 
</HTML>

Open in new window

0
Comment
Question by:Isaac
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:aldanch
ID: 24197237
It looks like you would need to modify "postFiles.php" judging from this script. We will need to see the contents of that file since it is what is handling the upload.

You may be able to look at it and see somewhere to add accepted extensions.
0
 
LVL 5

Author Comment

by:Isaac
ID: 24197489
The code I uploaded is the whole file.
That's all the code.
0
 
LVL 8

Expert Comment

by:aldanch
ID: 24197533
I don't see anything in the code that filters the files that are uploaded except for file size. Are you sure the .xps you are uploading isn't over 19MB?
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.

 
LVL 8

Expert Comment

by:aldanch
ID: 24197582
You should probably also change you MAX_FILE_SIZE to 20000000 instead of 10000000.

Line #43 in your script says no larger than 19MB but your MAX_FILE_SIZE is set to 10MB on line #85.

Perhaps your .xps file is larger than 10MB?
0
 
LVL 5

Author Comment

by:Isaac
ID: 24197650
I already tried changing it the max file but it still does not load.  The .xps file is 21.2MB and I change MAX_FILE_SIZE to 30000000 but it still does not upload.  It does not even let me know if the file size is too big.
0
 
LVL 8

Accepted Solution

by:
aldanch earned 2000 total points
ID: 24197693
You should also check your php ini file and make sure the following setting aren't too low.

post_max_size
upload_max_filesize
memory_limit

All of these setting affect you maximum upload size.
0
 
LVL 5

Author Closing Comment

by:Isaac
ID: 31572914
Thank you aldanch!
That's exactly what the problem was.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month15 days, 9 hours left to enroll

850 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