Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Odd Problems after Upgrade to v5.2.1 1

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
After upgrading from the last v 4x version of PHP to the most recent v 5.2.1, the site runs but has some odd problems that I cannot seem to solve. I hope someone can help quickly as I am in a bind!

First, it loads a JavaScript menu which also contains SQL and PHP in order to be dynamic. The PHP code for loading it is as follows:

Code:
if ($GetLogin) {
	ob_start();
	include("misc/system_menu.js");
	$contents = ob_get_contents();
	ob_end_clean();
	echo "<script type=\"text/javascript\">" . $contents . "</script>";
}

The menu appears but, except for a couple hard-coded entries, it's empty and when viewing the source code of the page, it shows <?php $ItemName ?> rather than the actual values.

Also, the site has a facility for viewing uploaded MS-Word, MS-Excel (etc) documents in a new browser window. Although the mime-type is being sent to the header and they WERE working, now they load but the browser is empty.

One last thing, phpinfo() shows that the magic_mime file is invalid and has not loaded. I realize that magic_mime has been depreciated but I am not sure how else to do the job as I have never used PEAR.

This is running on IIS6, Windows 2003 Server.

Any ideas? Thanks.

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
I found the problem with the menu! In php.ini, "short_open_tag = Off" is apparently the default for PHP v 5.2.1 but needs to be set to On for this menu to work. <?php=$ItemName?> doesn't work for some reason but <?=$ItemName?> does if short tags are enabled!

Any ideas on the other question? Can they be related? Although the site is passing the header with the correct mime type for viewing the uploaded files, the browser isn't getting the message. A plug-in is loading because there are extra buttons in the browser when trying to view a document but the document itself is not there.

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
Any ideas on this? When I updated the PHP on my development system, it does the same thing. Also, a WYSIWYG editor that the administration form uses also shows as empty when there is text in the field and I am sure it's the same problem. Since it does it with PHP 5.2.1 on two different systems, it must be some PHP configuration that I cannot locate. Please help!

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
use fileinfo() instead.


guesscontenttype() is deprecated but it still works. just point your php.ini towards the right magic_mime file. you do need to do this in php.ini and not httpd.conf. make sure that the php service (i.e. your webserver typically) has read access to the file.
 
Thanks! Yes, I neglected to say that magic_mime appears to be loading now. Although I thought at first that it was, the problem doesn't appear to be related to mime as the correct plug-in does indeed load but when it loads, the document has no content. I am looking into fileinfo() but is there anything else to look at?

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
not sure what the behaviour is that you're complaining of. can you give more info?
 
I have some Word, Excel and PDF documents that are linked using PHP code that supplies the headers and opens them up in a new browser window. After upgrading to PHP 5.2.1, the appropriate browser plug-in still loads but the documents appear empty in the browser. Here is the code used for fetching them.

Note that I need to do it via PHP rather than linking to them directly because the file name in the database changes if they are updated (a timestamp is prepended to the name):

Code:
if ($FileName) {
	$OriginalDoc = "/uploads/" . urldecode($FileName);
	$PathParts = pathinfo($OriginalDoc);
	$FileType = substr(strrchr($PathParts, "."), 1);
	//possible types: pdf, xls, doc, ppt, pps
	switch ($FileType) {
		case "pdf":
			$MimeType = "pdf";
	break;
		case "xls":
			$MimeType = "vnd.ms-excel";
	break;
		case "doc":
			$MimeType = "msword";
	break;
		case "ppt":
			$MimeType = "vnd.ms-powerpoint";
	break;
		case "pps":
			$MimeType = "vnd.ms-powerpoint";
	break;
		default:
			$MimeType = $FileType;
	}

	header("Content-type: application/".$MimeType);
	header("Content-Disposition: download; filename=".$FileName);
	header("Content-Transfer-Encoding: binary\n");
	readfile($OriginalDoc);
} else {
	echo "<span class=\"ErrorMessage\">The document could not be found.</span>";
}

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
try this instead, it handles file names with spaces

Code:
    header("Content-Disposition: download; filename=\"$FileName\"");

you should also provide a filesize for the browser
Code:
header("Content-Length: " . filesize($FileName) );

if these don't work then you should do some debugging to check whether you are addressing the files properly and have read access to them etc.
 
Thanks for the ideas! Odd but after making the suggested changes, attempting to view an MS-Word document started some kind of Windows Installer but it did not indicate what it was trying to install and, once it was done, the files still have no content. Excel files now give an error that the file cannot be found even though they are there and have the name it says it can't find. PDFs give yet another error that it can't open the file, then it opens Acrobat Reader with no file rather than opening in the browser as it should. All this worked before upgrading PHP - same files, same permissions etc. so I'm not sure what to debug!

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
this
Code:
header("Content-Length: " . filesize($FileName) );
should be a reference to
Code:
header("Content-Length: " . filesize($OriginalDoc) );

the behaviour that you otherwise describe seems more likely to be linked to the script not being able to get to the file you want to download.
 
I think we're on the right track but I had tried the suggestion earlier and still got the same errors/issues. I did notice that on Excel files, the tab that should show the sheet name is instead giving an odd variation of part of the file name:

.xls]200703221321350.Conferen

When I echo $FileName and $OriginalDoc to the screen, they are proper:

200703221321350.Conference_Rooms.xls
/uploads/200703221321350.Conference_Rooms.xls

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
try this then (as a debug)

Code:
if (is_readable("/uploads/200703221321350.Conference_Rooms.xls")){
 echo "can read the file";
}else{
 echo "cannot read the file";
}
 
Excellent idea! I was hoping that whatever was causing these files to not show was also the cause of the WYSIWYG editor coming up empty but, as it shows "cannot read the file", that is probably not the case. I am not sure WHY it cannot read the file as they were fully readable in the older version of PHP and I see nothing wrong with the permissions now. Does this version require something different? Thanks!

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
just check the permissions of the relevant directory. make sure that the php process can read the files. the relevant user should be something like IUSR_[MACHINENAME]

remember too that if you are trying to use a relative path (i.e. a path relative to the script) then omit the starting slash. if it is a path that is absolute to the webroot then you need the slash. i find, on windows systems, it is better to provide the full path (c:/path/etc). use forward slashes instead of backslashes (or use double backslashes).
 
Thanks, I am looking into the permissions now and so far they seem okay but I'll post when I get anywere. As for the path, I would prefer to use the full path but as it's different between the development system and the server, I chose the absolute path.

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
One thing, the IUSR permissions are set in IIS. Is it necessary to set them again in the filesystem and, if so, how will it affect other users if they're set to my machine name? There does not appear to be a generic IUSR_[MACHINENAME] user. Thanks.

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
The permissions all seem to be set properly and, in spite the message that the file cannot be read, it works perfectly if loaded directly into the browser (and it worked in v4.6):

uploads/200703221321350.Conference_Rooms.xls

Can you think of anything else - maybe some php.ini setting that might have a different default between v4.6 and v5.2.1 that could help?

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
the file name you posted in the post immediately above is different to the others. it is missing the opening slash.

try
Code:
if (is_readable("uploads/200703221321350.Conference_Rooms.xls")){
 echo "can read the file";
}else{
 echo "cannot read the file";
}
 
try using a file reference instead. c:/directory etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top