Jump to content

Problem uploading this style of word doc


Drummin

Recommended Posts

I'm working on a portal project for a school and they make weekly flyers like the one attached below.  Now if the file attaches to this post, then at least I know some script changes will fix the problem.  The school has an archive of hundreds of these docs they'd like to load up, so I need a solution.

I've made many versions of my upload script, which have been working fine for any word documents I create, but not for their word docs.

This is the code in my latest version.

<?php 
require("checkpass2.php");
require("../teacher/checkpass.php");
require("../access.inc.php"); 

mysql_connect("$host","$login","$pass") OR DIE
        ("There is a problem with the system.  Please notify your system administrator." .mysql_error());

mysql_select_db("$db") OR DIE
        ("There is a problem with the system.  Please notify your system administrator." .mysql_error());
include("../commonsettings.php");

IF ($_POST['upload']){
//$directory="$siteurl"; 
$directory=".."; 
$section=$_POST['section'];	
$directoryname = preg_replace('/[^a-zA-Z]/', '', $section);
$directlevel="$directory/$directoryname";
if(!file_exists($directlevel, 0777)) 
{ 
mkdir($directlevel);
}


$target_path = "$directlevel/";	 
$loaddate = date('MY');	 


$filename = preg_replace('/\s+/', '', $_FILES['uploadedfile']['name']);	
$file_basename = substr($filename, 0, strripos($filename, '.')); // strip extention
$file_ext = substr($filename, strripos($filename, '.')); // strip name
$filesize = $_FILES["uploadedfile"]["size"];

if (($file_ext == ".doc" || $file_ext == ".docx")  &&  ($filesize < 200000)) {
	// rename file
	$newfilename = $file_basename."_Uploaded_".date('M-Y') . $file_ext;

$nfilename = $newfilename;

	if (file_exists($target_path . $newfilename)) {
	unlink($target_path . $newfilename);
	mysql_query("DELETE FROM ".$conf['tbl']['uploads']." WHERE filename='$nfilename' AND section='$directoryname'") or die(mysql_error());

	} 
	if (!file_exists($target_path . $newfilename)) {
		move_uploaded_file($_FILES["uploadedfile"]["tmp_name"], $target_path . $newfilename);

$result = mysql_query("INSERT INTO ".$conf['tbl']['uploads']." SET filename='$nfilename', section='$directoryname'") or die(mysql_error());

header("Location:UploadFiles.php");
	}
} elseif (empty($file_basename)) {
	// file type error
	header("Location:UploadFiles.php?error=1");
	} else {
	// file selection error
	header("Location:UploadFiles.php?error=2");
	}

}
?>

Any help greatly appreciated.

 

[attachment deleted by admin]

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.