Jump to content

Recommended Posts

Hi,

Just a quick question. which Im sure one of you can answer very quickly.

My code
[code]<?PHP

if (ereg(".inc.php",$HTTP_SERVER_VARS['PHP_SELF'])) {
echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
exit;
}

$target = "rosco/";
$target = $target . basename( $_FILES['uploaded']['name']);
$ok=1;

//This is the size condition
if ($uploaded_size > 100) {
$errorMsg = $lang['front']['upload']['error_filesize'];
$ok=0;

//This is the type condition
} elseif (!($uploaded_type=="image/gif")) {
$errorMsg = $lang['front']['upload']['error_filetype'];
$ok=0;

//Here we check that $ok was not set to 0 by an error
} elseif ($ok==0) {
$errorMsg = $lang['front']['upload']['upload_failed'];

} else {

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {

$upload = new XTemplate ("skins/".$config['skinDir']."/styleTemplates/content/upload.tpl");

$upload->assign("LANG_UPLOAD_TITLE",$lang['front']['upload']['upload_title']);

if(isset($ok) == 1) {
$upload->assign("LANG_UPLOAD_DESCRIPTION",$lang['front']['upload']['upload_success']);
$upload->parse("upload.session_true.no_error");
} elseif(isset($errorMsg)) {
$upload->assign("VAL_ERROR",$errorMsg);
$upload->parse("upload.session_true.error");
} else {
$upload->assign("LANG_UPLOAD_DESCRIPTION",$lang['front']['upload']['upload_description']);
$upload->parse("upload.session_true.no_error");
}


if($ccUserData[0]['customer_id']>0) {

$upload->parse("upload.session_true");

} else {
$upload->assign("LANG_LOGIN_REQUIRED",$lang['front']['upload']['login_required']);
$upload->parse("upload.session_false");


}
}

$upload->parse("upload");
$page_content = $upload->text("upload");
?>[/code]

The error
[code]Parse error: syntax error, unexpected $end in /home/semperfi/public_html/cubecartservices/includes/content/upload.inc.php on line 88[/code]

Any help getting this fixed would be greatly appreciated :)
Link to comment
https://forums.phpfreaks.com/topic/15069-a-very-quick-question/
Share on other sites

[quote author=hitman6003 link=topic=101141.msg400079#msg400079 date=1153352874]
Which line is 86?
[/quote]

[quote]Errr... There are no includes, no requires, no $end variable, and its less then 88 lines long.[/quote]

it is also less then 86 lines long. Its a syntax error somewhere in there creating an odd error.
Link to comment
https://forums.phpfreaks.com/topic/15069-a-very-quick-question/#findComment-60710
Share on other sites

Sorry for the lack of info, been back and forth all day.

The code above is from a file called upload.inc.php

Its called via index.php with this:
[code] case "upload":
include("includes/content/upload.inc.php");
$body->assign("PAGE_CONTENT",$page_content);
break; [/code]

And as you can see, the html side of things is handled by upload.tpl

As for what line 86 is, that would be :
[code]74 if($ccUserData[0]['customer_id']>0) {
75
76 $upload->parse("upload.session_true");
77
78 } else {
79 $upload->assign("LANG_LOGIN_REQUIRED",$lang['front']['upload']['login_required']);
80 $upload->parse("upload.session_false");
81
82
83 }
84 }
85 }
86 $upload->parse("upload");
87 $page_content = $upload->text("upload");
88 ?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/15069-a-very-quick-question/#findComment-60725
Share on other sites

what does the entire parse error say?  usually it should be easy to figure out a function call on a non-object, since i think it says which variable you're trying to call a member function.

either way, what it means is that an object you're calling a method from hasn't been initialized properly, or it's been differently named, etc.  the full parse error will help in tracking down where it is and which file it's from.
Link to comment
https://forums.phpfreaks.com/topic/15069-a-very-quick-question/#findComment-60853
Share on other sites

it's because you're calling a method on $upload OUTSIDE of the else{} statement - this will fail if the move_uploaded_file() if() condition fails, because you're only calling the object from within that branch.  if you don't execute that branch, $upload will never have been created.
Link to comment
https://forums.phpfreaks.com/topic/15069-a-very-quick-question/#findComment-61667
Share on other sites

Perhaps...

[code]
<?PHP

if (ereg(".inc.php",$HTTP_SERVER_VARS['PHP_SELF'])) {
echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
exit;
}

$target = "rosco/";
$target = $target . basename( $_FILES['uploaded']['name']);
$ok=1;

//This is the size condition
if ($uploaded_size > 100) {
$errorMsg = $lang['front']['upload']['error_filesize'];
$ok=0;

//This is the type condition
} elseif (!($uploaded_type=="image/gif")) {
$errorMsg = $lang['front']['upload']['error_filetype'];
$ok=0;

//Here we check that $ok was not set to 0 by an error
} elseif ($ok==0) {
$errorMsg = $lang['front']['upload']['upload_failed'];

} else {

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {

$upload = new XTemplate ("skins/".$config['skinDir']."/styleTemplates/content/upload.tpl");

$upload->assign("LANG_UPLOAD_TITLE",$lang['front']['upload']['upload_title']);

if(isset($ok) == 1) {
$upload->assign("LANG_UPLOAD_DESCRIPTION",$lang['front']['upload']['upload_success']);
$upload->parse("upload.session_true.no_error");
} elseif(isset($errorMsg)) {
$upload->assign("VAL_ERROR",$errorMsg);
$upload->parse("upload.session_true.error");
} else {
$upload->assign("LANG_UPLOAD_DESCRIPTION",$lang['front']['upload']['upload_description']);
$upload->parse("upload.session_true.no_error");
}


if($ccUserData[0]['customer_id']>0) {

$upload->parse("upload.session_true");

} else {
$upload->assign("LANG_LOGIN_REQUIRED",$lang['front']['upload']['login_required']);
$upload->parse("upload.session_false");
}

            $upload->parse("upload");
            $page_content = $upload->text("upload");
} else {
            // Error message. Upload failed
            die("Error Uploading!");
}

?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/15069-a-very-quick-question/#findComment-61706
Share on other sites

Thanks for the reply HeyRay2 :)

Before I try that, here is an example of an include file that does work

[code]<?php
/*
+--------------------------------------------------------------------------
|  CubeCart v3.0.10
|  ========================================
|  by Alistair Brookbanks
| CubeCart is a Trade Mark of Devellion Limited
|  Copyright Devellion Limited 2005 - 2006. All rights reserved.
|  Devellion Limited,
|  22 Thomas Heskin Court,
|  Station Road,
|  Bishops Stortford,
|  HERTFORDSHIRE.
|  CM23 3EE
|  UNITED KINGDOM
|  http://www.devellion.com
| UK Private Limited Company No. 5323904
|  ========================================
|  Web: http://www.cubecart.com
|  Date: Tuesday, 14th March 2006
|  Email: info (at) cubecart (dot) com
| License Type: CubeCart is NOT Open Source Software and Limitations Apply
|  Licence Info: http://www.cubecart.com/site/faq/license.php
+--------------------------------------------------------------------------
| profile.inc.php
|  ========================================
| Customers Profile
+--------------------------------------------------------------------------
*/

if (ereg(".inc.php",$HTTP_SERVER_VARS['PHP_SELF'])) {
echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
exit;
}

// send email if form is submit
if(isset($_POST['submit']) && $ccUserData[0]['customer_id']>0){

if($_POST['email']!==$ccUserData[0]['email']){
$emailArray = $db->select("SELECT customer_id, type FROM ".$glob['dbprefix']."CubeCart_customer WHERE email=".$db->mySQLSafe($_POST['email']));
}

if(empty($_POST['firstName']) || empty($_POST['lastName']) || empty($_POST['email']) || empty($_POST['phone']) || empty($_POST['add_1']) || empty($_POST['town']) || empty($_POST['county']) || empty($_POST['postcode']) || empty($_POST['country']) || empty($_POST['companyName']) || empty($_POST['siteURL'])){

$errorMsg = $lang['front']['profile']['complete_all'];

} elseif(validateEmail($_POST['email'])==FALSE) {

$errorMsg = $lang['front']['profile']['email_invalid'];

} elseif(!ereg("[0-9]",$_POST['phone'])) {

$errorMsg = $lang['front']['profile']['enter_valid_tel'];

} elseif(!empty($_POST['mobile']) && !ereg("[0-9]",$_POST['mobile'])) {

$errorMsg = $lang['front']['profile']['enter_valid_tel'];

} elseif(isset($emailArray) && $emailArray == TRUE && $emailArray[0]['type']==1) {

$errorMsg = $lang['front']['profile']['email_inuse'];

} else {

// update database
$data['title'] = $db->mySQLSafe($_POST['title']);
$data['firstName'] = $db->mySQLSafe($_POST['firstName']);
$data['lastName'] = $db->mySQLSafe($_POST['lastName']);
$data['email'] = $db->mySQLSafe($_POST['email']);
$data['add_1'] = $db->mySQLSafe($_POST['add_1']);
$data['add_2'] = $db->mySQLSafe($_POST['add_2']);
$data['town'] = $db->mySQLSafe($_POST['town']);
$data['county'] = $db->mySQLSafe($_POST['county']);
$data['postcode'] = $db->mySQLSafe($_POST['postcode']);
$data['country'] = $db->mySQLSafe($_POST['country']);
$data['phone'] = $db->mySQLSafe($_POST['phone']);
$data['mobile'] = $db->mySQLSafe($_POST['mobile']);
$data['companyName'] = $db->mySQLSafe($_POST['companyName']);
$data['siteURL'] = $db->mySQLSafe($_POST['siteURL']);

// look up users zone
$zoneId = $db->select("SELECT * FROM ".$glob['dbprefix']."CubeCart_iso_counties WHERE (abbrev LIKE '".addslashes_gpc($_POST['county'])."' OR name LIKE '".addslashes_gpc($_POST['county'])."')");

if($zoneId[0]['id']>0){

$data["zoneId"] = $zoneId[0]['id'];

} else {

$data["zoneId"] = 0;

}

$where = "customer_id = ".$ccUserData[0]['customer_id'];
$updateAcc = $db->update($glob['dbprefix']."CubeCart_customer",$data,$where);

// make email
include("classes/htmlMimeMail.php");

$mail = new htmlMimeMail();

$text = sprintf($lang['front']['profile']['update_email'],$_POST['firstName'],$_POST['lastName'],$GLOBALS['storeURL'],$_SERVER['REMOTE_ADDR']);

$mail->setText($text);
$mail->setFrom($config['masterName'].' <'.$config['masterEmail'].'>');
$mail->setSubject($lang['front']['profile']['update_email_subj']);
$mail->setHeader('X-Mailer', 'CubeCart Mailer');
$send = $mail->send(array($_POST['email']), $config['mailMethod']);

if(isset($_GET['f']) && !empty($_GET['f'])){
header("Location: cart.php?act=".$_GET['f']);
}

// rebuild customer array
$query = "SELECT * FROM ".$glob['dbprefix']."CubeCart_sessions INNER JOIN ".$glob['dbprefix']."CubeCart_customer ON ".$glob['dbprefix']."CubeCart_sessions.customer_id = ".$glob['dbprefix']."CubeCart_customer.customer_id WHERE sessId = '".$_SESSION['ccUser']."'";
$ccUserData = $db->select($query);
}
}

$profile = new XTemplate ("skins/".$config['skinDir']."/styleTemplates/content/profile.tpl");

$profile->assign("LANG_PERSONAL_INFO_TITLE",$lang['front']['profile']['personal_info']);

if(isset($updateAcc) && $updateAcc == TRUE) {
$profile->assign("LANG_PROFILE_DESC",$lang['front']['profile']['account_updated']);
$profile->parse("profile.session_true.no_error");
} elseif(isset($errorMsg)) {
$profile->assign("VAL_ERROR",$errorMsg);
$profile->parse("profile.session_true.error");
} else {
$profile->assign("LANG_PROFILE_DESC",$lang['front']['profile']['edit_below']);
$profile->parse("profile.session_true.no_error");
}

if($ccUserData[0]['customer_id']>0) {

if(isset($_GET['f']) && !empty($_GET['f'])){
$profile->assign("VAL_EXTRA_GET","&amp;f=".$_GET['f']);
}

$profile->assign("TXT_TITLE",$lang['front']['profile']['title']);
$profile->assign("VAL_TITLE",$ccUserData[0]['title']);

$profile->assign("TXT_FIRST_NAME",$lang['front']['profile']['first_name']);
$profile->assign("VAL_FIRST_NAME",$ccUserData[0]['firstName']);

$profile->assign("TXT_LAST_NAME",$lang['front']['profile']['last_name']);
$profile->assign("VAL_LAST_NAME",$ccUserData[0]['lastName']);

$profile->assign("TXT_EMAIL",$lang['front']['profile']['email']);
$profile->assign("VAL_EMAIL",$ccUserData[0]['email']);

$profile->assign("TXT_ADD_1",$lang['front']['profile']['address']);
$profile->assign("VAL_ADD_1",$ccUserData[0]['add_1']);

$profile->assign("TXT_ADD_2","");
$profile->assign("VAL_ADD_2",$ccUserData[0]['add_2']);

$profile->assign("TXT_TOWN",$lang['front']['profile']['town']);
$profile->assign("VAL_TOWN",$ccUserData[0]['town']);

$profile->assign("TXT_COUNTY",$lang['front']['profile']['county']);
$profile->assign("VAL_COUNTY",$ccUserData[0]['county']);

$profile->assign("TXT_POSTCODE",$lang['front']['profile']['postcode']);
$profile->assign("VAL_POSTCODE",$ccUserData[0]['postcode']);

$profile->assign("TXT_COUNTRY",$lang['front']['profile']['country']);


$countries = $db->select("SELECT id, printable_name FROM ".$glob['dbprefix']."CubeCart_iso_countries ORDER BY printable_name");

for($i=0; $i<count($countries); $i++){


if($countries[$i]['id'] == $ccUserData[0]['country']){
$profile->assign("COUNTRY_SELECTED","selected='selected'");
} else {
$profile->assign("COUNTRY_SELECTED","");
}

$profile->assign("VAL_COUNTRY_ID",$countries[$i]['id']);

$countryName = "";
$countryName = $countries[$i]['printable_name'];

if(strlen($countryName)>20){

$countryName = substr($countryName,0,20)."&hellip;";

}

$profile->assign("VAL_COUNTRY_NAME",$countryName);

$profile->parse("profile.session_true.country_opts");

}

$profile->assign("VAL_COUNTRY",$ccUserData[0]['country']);

$profile->assign("TXT_PHONE",$lang['front']['profile']['phone']);
$profile->assign("VAL_PHONE",$ccUserData[0]['phone']);

$profile->assign("TXT_MOBILE",$lang['front']['profile']['mobile']);
$profile->assign("VAL_MOBILE",$ccUserData[0]['mobile']);

$profile->assign("TXT_COMPANYNAME",$lang['front']['profile']['companyname']);
$profile->assign("VAL_COMPANYNAME",$ccUserData[0]['companyName']);

$profile->assign("TXT_SITEURL",$lang['front']['profile']['siteurl']);
$profile->assign("VAL_SITEURL",$ccUserData[0]['siteURL']);

$profile->assign("TXT_SUBMIT",$lang['front']['profile']['update_account']);

$profile->parse("profile.session_true");

} else {
$profile->assign("LANG_LOGIN_REQUIRED",$lang['front']['profile']['login_required']);
$profile->parse("profile.session_false");

}

$profile->parse("profile");
$page_content = $profile->text("profile");
?>[/code]

Link to comment
https://forums.phpfreaks.com/topic/15069-a-very-quick-question/#findComment-61712
Share on other sites

The working code example you mention calls a method on an object ([B]$Profile[/B]) regardless of whether or not a form has been submitted.

Your code will fail with the "method on a non-object" if the following conditional is false:

[code=php:0]
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
[/code]

This is because the [B]$upload[/B] object will not be defined in this case. You need to ensure that you don't make calls on [B]$upload[/B] if you have not defined it. That's what my code change does for you. The only part of your code I changed is the last 5 lines from:

[code=php:0]
}
}

$upload->parse("upload");
$page_content = $upload->text("upload");
[/code]

to:

[code=php:0]
            $upload->parse("upload");
            $page_content = $upload->text("upload");
  } else {
            // Error message. Upload failed
            die("Error Uploading!");
  }

}
[/code]

Did you try my change? Did it make any difference?
Link to comment
https://forums.phpfreaks.com/topic/15069-a-very-quick-question/#findComment-65146
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.