Solved

php script failing with converted word perfect file (converted to word doc)

Posted on 2008-10-21
5
228 Views
Last Modified: 2012-05-05
For some reason my upload script is failing with a particular file, a Word Perfect file that was converted to a doc file (97-2003). It throws off the whole system for some reason. I wish I could attach it but the information is private. The only guess that I have is that somehow the metadata is bad. However, I looked at it in windows explorer and it everything looks fine. My guess is that it has something to do with this line:

        //Attempt to move the uploaded file to it's new place
        copy($_FILES['File']['tmp_name'],"$folder".$_FILES['File']['name']);
      
I opened the file in Word and then resaved it. After that, it worked fine. Is there some way to catch this? Has anyone ever experienced this before?

Thanks in advance for your help!
0
Comment
Question by:sherlock5
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 17

Expert Comment

by:psimation
ID: 22770217
what is the filename of the doc before you try to upload?

0
 

Author Comment

by:sherlock5
ID: 22770597
it has the .doc extension.
0
 

Author Comment

by:sherlock5
ID: 22770722
i will have to post my script tomorrow... i just tried a simple script(http://www.phpeasystep.com/phptu/1.html) and i was able to upload the file... so something is wrong with my code. it is weird though that it worked for all of the files except for this one. i will post my code tomorrow... thanks for responding psimation.
0
 

Author Comment

by:sherlock5
ID: 22802166
sorry for the amount of time it took to post my code...

once again, for some reason i'm having trouble uploading a doc file that was saved in wordperfect. this script works for everything else but seems to fail with this one file. i also tried this script and i was able to upload the doc file (http://www.phpeasystep.com/phptu/1.html). i figure that the problem is more with my code... which is very messy, i know, and i'm willing to listen to how i can improve it.

the problem that occurs when i load the wordperfect/word doc file is that all of the folders in the files folder are listed like this:

id (path/to/files//id)  4.00KB   remove
.
.
.

... and all of the hidden variables in the form disappear after the post or upload.

so, if anyone can help me, that would be swell!
<?
########### Connection to database ##################################################
connection goes here...
#####################################################################################
 
 
##### file functions #####
function fileDelete($filepath,$filename) {
$success = FALSE;
if (file_exists($filepath.$filename)&&$filename!=""&&$filename!="n/a") {
unlink ($filepath.$filename);
$success = TRUE;
}
return $success;
}
 
 
function countFiles($strDirName)
{
if ($hndDir = @opendir($strDirName))
{
$intCount = 0;
while (false !== ($strFilename = @readdir($hndDir)))
{
if ($strFilename != "." && $strFilename != "..")
{
$intCount++;
}
}
@closedir($hndDir);
}
else
{
$intCount = -1;
}
 
return $intCount;
}
 
function size($size, $short = false) {
  if ($short) {
    $unit = array(
      'B', 'KB', 'MB', 'GB', 'TB',
      'PB', 'EB', 'ZB', 'YB'
     );
  } else {
    $unit = array(
      'bytes', 'kilobyte', 'megabyte',
      'gigabyte', 'terabyte', 'petabyte',
      'exabyte', 'zettabyte', 'yottabyte'
     );
  }
 
  $base = floor(log($size, 1024));
  return round($size / pow(1024, $base), 2).' '.$unit[$base];
}
 
 
if($_REQUEST["id"]) { 
$id = $_REQUEST["id"]; 
 
} else { 
$id = $_REQUEST["ID"];
}
 
if($id) {
// check to see if paper has been published
$s7 = "SELECT T FROM W WHERE ID=$id ORDER BY R DESC LIMIT 1";
$r7 = @mysql_query($s7);
$c7 = @mysql_fetch_row($r7);
$live = "$c7[0]";
}
 
if($_REQUEST["live"] == "live") {
echo "<font color=red>We are sorry but you can no longer edit this...</font>";
} else {
 
?>
<h1>Form</h1>
 
<p><a href="form.php?Submit=Submit&Code=<?=$_REQUEST["Code"];?>&Email=<?=$_REQUEST["Email"]?>"\">Go back.</a></p>
<form name="form" method="post" enctype="multipart/form-data" action="<? echo $_SERVER['PHP_SELF'];?>">
	<table border="0" cellspacing="2" cellpadding="2">
	<tr>
	<th>Attach Files</th>
	</tr>
	<tr><td><p>Upload files here...</p> Fields with a <span class="error">*</span> are required.<br></td>
	</tr>
	<tr class="even">
	<td>Upload File:<span class="important"> *</span></td>
	</tr>
	<tr class="even">
	<td><input type="file" name="File" size="50"><input type="hidden" name="ID" value="<?=$id;?>"></td>
	</tr>
	<tr>
	<td><p><input name="Upload" type="submit" class="formbutton" value=" Upload "></p></td>
	</tr>
<?
 
	  $r = $_REQUEST["delete"];
	  if ($_FILES['File']['name'] == "" && ($r[0] == "A" || $r == "") && isset($_REQUEST["Upload"])) {
	  echo "<span class=\"error\"><img src=\"error.gif\" />You did not submit a file!</span>";
	  } elseif(!preg_match("/(doc)/i",$_FILES['File']['name']) && ($r[0] == "A" || $r == "") && isset($_REQUEST["Upload"])) {
	  echo "<span class=\"error\"><img src=\"error.gif\" />The file you have submitted is not a doc!</span>";
	  } elseif ($_FILES['File']['size'] > 31457280 && ($r[0] == "A" || $r == "") && isset($_REQUEST["Upload"])) {
	  echo "<span class=\"error\"><img src=\"error.gif\" />The file is larger than 30MB...</span";
	  }
 
if (preg_match("/(doc)/i",$_FILES['File']['name']) && $_FILES['File']['size'] < 31457280 && isset($_REQUEST["Upload"]) && $_FILES['File']['size'] > 0) {
 
 
 
$cf = countFiles("../path/to/files/$id/");
 
if( $cf < 31 && $_REQUEST["Upload"]) { 
$folder = $_SERVER['DOCUMENT_ROOT']."/path/to/files/$id/";
 
if(!(is_dir($folder))) {
mkdir($folder,0777);
}
 
      //Check if the file with the same name is already exists on the server
      if (!file_exists($folder.$_FILES['File']['name'])) {
        //Attempt to move the uploaded file to it's new place
        copy($_FILES['File']['tmp_name'],"$folder".$_FILES['File']['name']);
		} else {
		echo "<span class=\"error\"><img src=\"error.gif\" />The file you are uploading already exists!</span>";
		}
		
} else {
echo "<span class=\"error\"><img src=\"error.gif\" />You have reached the limit of uploads...</span>";
}
 
}
 
if ($_REQUEST["DeleteFiles"]) {
// remove files
$x = $_REQUEST["delete"];
for ($i=0; $i < count($x); $i++) {
		$filepath = $_SERVER['DOCUMENT_ROOT']."/path/to/files/$id/";
		fileDelete($filepath,$x[$i]); 
			}
}
 
 
 
echo "<tr>\n\r<td colspan=\"2\">\n\r";
echo "<h3>Uploaded Files</h3>\n\r<code>";
 
				   $path = $_SERVER['DOCUMENT_ROOT']."/path/to/files/$id/";
				   $dh = @opendir($path);
				   
				   while (false !== ($file=@readdir($dh)))
				   {
				   if (substr($file,0,1)!="." && !stristr($file, "filter"))
				   $files[]=array(filemtime($path.$file),filesize($path.$file),$file);
				   }
				   @closedir($dh);
				   if ($files)
				   {
				   rsort($files);
				   
				   foreach ($files as $file)
				   echo "<a href=\"../path/to/files/$id/$file[2]\" target=\"_blank\">$file[2]</a> &nbsp;<em>".number_format(($file[1]/1024),2)."KB</em> &nbsp;<input name=\"delete[]\" type=\"checkbox\" value=\"$file[2]\"> <sup><span class=\"error\">remove</span></sup><br>\n\r";
				   }
				
		echo "\n\r<br><input name=\"DeleteFiles\" type=\"submit\" class=\"formbutton\" value=\" Remove \"></code>\n\r</td></tr>";
		echo "<tr>\n\r<td align=\"center\" colspan=\"2\">\n\r";
		echo "</td></tr></table>";
		echo "<input name=\"Emails\" type=\"hidden\" value=\"$_REQUEST[Email]\">";
		echo "<input name=\"Code\" type=\"hidden\" value=\"$_REQUEST[Code]\">";
		echo "<input name=\"live\" type=\"hidden\" value=\"$live\">";
		echo "</form>";
}
 
		?>

Open in new window

0
 

Accepted Solution

by:
sherlock5 earned 0 total points
ID: 23105097
i fixed this a while ago... turns out i just needed this in an htaccess file:

php_value post_max_size 30M
php_value upload_max_filesize 30M
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

733 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