Helpful Information
 
 
Category: Linux
Linux -> Windows Conversion to enable PopCard

At this test position (http://www.newtest.webitry.net/popcard.php) I have installed PopCard (http://www.pixaria.com/popcard/) script. It needs to be altered for use on Windows.

To progress this in respect of the location of the temp folder I have changed line 61 in config.php from

define("POPC_TEMP_DIR","/var/tmp/");

to

define("POPC_TEMP_DIR","C:\Windows\Temp\");

However this now gives me a

Parse error: syntax error, unexpected T_STRING in C:\CustomerData\webspaces\webspace_00159712\wwwroot\newtest.webitry.net\resources\includes\popcard.config.php on line 72

see construction of line 72 in attached image. Why might line 72 be presenting a Parse error and is there a fix?

The following is the complete script of the config.php


<?php

/*
*
* PopCard 3.0
* Copyright 2002 - 2008 Jamie Longstaff
*
*/

// Prevent this script being executed outside of the PopCard scope
if (POPCARD != "ON") { print("Direct access to this script is not allowed."); exit; }

/*
*
* This file contains all the system settings that are specific to your webserver
*
*/

/*
*
* Initialise the configuration information array
* DO NOT REMOVE THESE LINES!
*
*/
$cfg = array();
$lang = array();
$style = array();

/*
*
* The system path to the folder or directory containing all your scripts
* You should NOT need to manually set this value
*
*/
define("POPC_BASE_PATH",dirname(dirname(dirname(__FILE__)))."/");

/*
*
* The length of time users have to pick and send a card
* Avoid making this calue longer than 1800 seconds to help prevent spam
*
*/
define("POPC_TIMEOUT",600);


/*
*
* Enter an e-mail address between the second pair of quote marks to send a copy of every card to:
*
* e.g. define("POPC_TIMEOUT","myemail@domain.com");
*
*/
define("POPC_COPY_TO","");


/*
*
* Set the location of the temp folder
*
*/
define("POPC_TEMP_DIR","/var/tmp/");


/*
*
* Set whether you have GD 2.0+ on your server (produces better results)
* The variable GD2 can be either "TRUE" or "FALSE"
*
*/
define("POPC_GD2",true);

/*
*
* Choose whether or not you want to enable postcards from remote images
*
* Can be either true or false
*
*/
define("POPC_REMOTE_IMAGES",true);

/*
*
* To restrict remote image access to one URL, enter it between the two
* quote marks or else leave blank to allow images from any URL to be used.
*
*/
define("POPC_REMOTE_URL","");

/*
*
* Quality of the JPEG file to be displayed as a preview when the
* user creates their custom message. The lowest quality setting is
* 0, the highest quality setting, 100, will output much larger files
*
*/
define("POPC_JPEG_QUALITY",90);

/*
* Distance (in pixels) from top edge of card to where text box starts
* Adjust this value to leave space for larger or smaller postmark images
*/
define("POPC_TEXT_OFFSET_TOP",75);

/*
*
* You can change the language by editing this constant and replacing it with
* one of the language codes specified below. If you translate PopCard into
* another language, why not e-mail it to info@pixaria.com to be included.
*
* de_DE Deutsch German
* dk_DK Dansk Danish
* en_GB British English
* es_ES Castellano (Español) Spanish
* fi_FI Suomi Finnish
* fr_FR Français French
* id_ID Bahasa Indonesian
* nl_NL Nederlands Netherlands Dutch
* no_NO Norsk (Nynorsk) Norwegian - Nynorsk
* pt_BR Português Brazilian Portuguese
* ro_RO Română Romanian
*
*/
define("POPC_LOCALISATION","en_GB");


?>

when you enter the windows-style path
"c:\windows\path\"; the backslash (which is an escape character) causes PHP to ignore the closing double-quote. In your image, notice how the double-quote and semicolon are highlighted as if they are part of the string. Your string is actually ending halfway through the comment section, where it says ..."TRUE...

Not sure if I am getting the resolve to the point you are highlighting. Whatever I try leads me back to the same place.... ie when I send (test) the card to my email address the message arrives but no card! :confused:

I might be missing something here... Did you fix the backslash issue? Are you still getting a parse error or not?

// this is wrong
define("POPC_TEMP_DIR","C:\Windows\Temp\");

// you need to escape the backslash
define("POPC_TEMP_DIR","C:\Windows\Temp\\");
is there another problem you're encountering now?

Not logging any errors at the moment. Having installed your line like so:

define("POPC_TEMP_DIR","C:\Windows\Temp\\");
I no longer get the server error, but the selected card is not being held on the form fill in page?

Wouldn't you need to escape all the backslashes? Like:


define("POPC_TEMP_DIR","C:\\Windows\\Temp\\");

And not only there, but also anywhere else you have them in strings, at least I would think. Standard practice for strings in almost any sort of code. Otherwise \W would either be just W or some special character, same with \T and so on if these appear elsewhere in strings in the code.

In PHP you only need to escape when it would specifically cause a problem. It's not the backslash that is the problem. It's the quote. In this very specific case, it ends up being the backslash, but because the backslash escapes (disables) the quote at the end. Backslashes are completely allowed in PHP except in a few cases where they make another character (or another backslash) escaped after them. So in short, no, just the backslash at the end before the quote.

Wouldn't you need to escape all the backslashes?
[...]
And not only there, but also anywhere else you have them in strings, at least I would think. Standard practice for strings in almost any sort of code. Otherwise \W would either be just W or some special character, same with \T and so on if these appear elsewhere in strings in the code.

with PHP, not necessarily (http://us2.php.net/manual/en/language.types.string.php) -- it's only required where the backslash would create an escape sequence. you could escape all of them to "play it safe," though - \ and \\ actually produce the same output:

<?php
// Outputs: You deleted C:\*.*?
echo 'You deleted C:\\*.*?';

// Outputs: You deleted C:\*.*?
echo 'You deleted C:\*.*?';

and, if you were to use single quotes instead of double quotes, you would only ever need to worry when the backslash precedes another single quote.

In the demo position (http://www.newtest.webitry.net/popcard.php) the additional backslash is in use as suggested as follows:

define("POPC_TEMP_DIR","C:\Windows\Temp\\"); however when a picture is selected it will not present or render on the next page of the demo?

Is it the case that the image data is not now being kept in the temp file to facilitate the form fillout and later mailing on send?

// -- Put image data into the temp file
$fp = fopen(POPC_TEMP_DIR . $time, "w");
fwrite($fp,$contents);
fclose($fp);

have you checked that the file is being written correctly?