PHP Issues on Windows Server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
olimess
Forum Newbie
Posts: 8
Joined: Sun Feb 10, 2008 12:07 pm

PHP Issues on Windows Server

Post by olimess »

Hi everyone.


I'm hoping one of you experts out there might be able to help me out with some issues I've been experiencing with my script. I'll try my best to explain what I have.

I've created a small PHP-based system for a client of mine. I built this system on my testing machine which is a Linux server with PHP 5.xx. My clients production machine is a Windows-based server, which also has the same version of PHP installed.

The system I built basically builds an order sheet based on information the user enters. The user can also attach files to the order. The order sheet is then saved to the server and is also emailed to the order desk and to the customer. My problem is that it doesn't always work on the Windows server but works 100% of the time on my testing machine. I've noticed several problems on the Windows server ... which I'll explain below. Yet what's odd is that it does work some of the time as well. Strange?!?

Initially a temporary folder is created for the user if the user adds files to their order. Later the contents of this folder is moved to a new folder, which is created by the script. My first question ... does it make a difference how I create and copy folders and content using PHP on the Windows server?

For example, I use the following to create folders:

Code: Select all

  // cleanup post data 
  function cleanup($data) {
	$data = ereg_replace("[^A-Za-z0-9 ]", "", $data);
        return $data;
  }

  $strCustomerName	= cleanup($_POST['strCustomerName']);
  $strSavePath = "_savedOrders/Customers/" . $strCustomerName . "/";
		
  if (!file_exists($strSavePath)) {
      mkdir($strSavePath, 0777, true);
  }
The above script should create a folder for the user using the defined path. The problem is that this doesn't always seem to work on the Windows server. What could be wrong and how can I go about checking that an error has occurred?

I use the following script to copy the contents of the temp folder to the new folder.

Code: Select all

function copyr($source, $dest) {
	// Simple copy for a file
	if (is_file($source)) {
		return copy($source, $dest);
	}

	// Make destination directory
	if (!is_dir($dest)) {
		mkdir($dest);
	}

	// Loop through the folder
	$dir = dir($source);
	while (false !== $entry = $dir->read()) {
		// Skip pointers
		if ($entry == '.' || $entry == '..') {
			continue;
		}
		// Deep copy directories
		if ($dest !== "$source/$entry") {
			copyr("$source/$entry", "$dest/$entry");
		}
	}

	// Clean up
	$dir->close();
	return true;
}

$strUploadPath	= "_upload/" . $strSessionID . "/";  //$strSessionID is defined earlier in the script

copyr($strUploadPath, $strSavePath);

Again, this appears to work some of the time but not at other times. The biggest problem is that at times is appears that all of the contents found under the _upload folder get's copied to the root of the server drive ... which is very strange because I wouldn't' think that any script would have the permission to do something like that ... even if it did mess up. I'm wondering if this issue is being caused by issues with the create folder script above?



Hopefully this makes sense. I look forward to your responses.

Thanks
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: PHP Issues on Windows Server

Post by egg82 »

windows disallows some characters when naming a folder. Check that list against your ereg_replace to be sure you catch every character

http://support.grouplogic.com/?p=1607
there's your character list for various operating systems
olimess
Forum Newbie
Posts: 8
Joined: Sun Feb 10, 2008 12:07 pm

Re: PHP Issues on Windows Server

Post by olimess »

Thanks for your response. I did check my script however and verified that the ereg_replace works as it should on both the testing server and the production server. Basically all unwanted characters will be stripped from the string using the cleanup function. The cleanup function only allows letters and numbers to remain.
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: PHP Issues on Windows Server

Post by egg82 »

did you check names as well?
There's a list of names not allowable in windows on the same link
olimess
Forum Newbie
Posts: 8
Joined: Sun Feb 10, 2008 12:07 pm

Re: PHP Issues on Windows Server

Post by olimess »

Yes ... I did. Thanks.
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: PHP Issues on Windows Server

Post by egg82 »

what file names are giving you issues, then?
It seems to me if we can find a pattern with that, we might be able to solve the problem
olimess
Forum Newbie
Posts: 8
Joined: Sun Feb 10, 2008 12:07 pm

Re: PHP Issues on Windows Server

Post by olimess »

That's the thing ... I can't seem to find any pattern at all, which is why I started thinking that perhaps it was a Windows server issue some how?
Post Reply