0

Hi,

I'm trying to implement some php code that I have in one document into another document.
However when I do that I get this error:
Parse error: syntax error, unexpected $end in /home/www/wearecrunch.dk/gammelsjuf/ajax/class/phUploader.php on line 470

I think it has something to do with where I'm placing the code, but not sure?

this is my code:

// Initialize variables
$password_hash=md5($password);
$error="";
$success="";
$display_message="";
$file_ext=array();
$password_form="";

// Function to get the extension a file.
function get_ext($key) { 
    $key=strtolower(substr(strrchr($key, "."), 1));
    $key=str_replace("jpeg","jpg",$key);
    return $key;
}

// Filename security cleaning. Do not modify.
function cln_file_name($string) {
    $cln_filename_find=array("/\.[^\.]+$/", "/[^\d\w\s-]/", "/\s\s+/", "/[-]+/", "/[_]+/");
    $cln_filename_repl=array("", ""," ", "-", "_");
    $string=preg_replace($cln_filename_find, $cln_filename_repl, $string);
    return trim($string);
}

// If a password is set, they must login to upload files.
If($password) {

    //Verify the credentials.
    If($_POST['verify_password']==true) {
        If(md5($_POST['check_password'])==$password_hash) {
            setcookie("phUploader",$password_hash);
            sleep(1); //seems to help some people.
            header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);

            exit;
            echo "1";
        }

    }


    //Show the authentication form
    If($_COOKIE['phUploader']!=$password_hash) {
        $password_form="<form method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n";
        $password_form.="<table align=\"center\" class=\"table\">\n";
        $password_form.="<tr>\n";
        $password_form.="<td width=\"100%\" class=\"table_header\" colspan=\"2\">Password Required</td>\n";
        $password_form.="</tr>\n";
        $password_form.="<tr>\n";
        $password_form.="<td width=\"35%\" class=\"table_body\">Enter Password:</td>\n";
        $password_form.="<td width=\"65%\" class=\"table_body\"><input type=\"password\" name=\"check_password\" /></td>\n";
        $password_form.="</tr>\n";
        $password_form.="<td colspan=\"2\" align=\"center\" class=\"table_body\">\n";
        $password_form.="<input type=\"hidden\" name=\"verify_password\" value=\"true\">\n";
        $password_form.="<input type=\"submit\" value=\" Verify Password \" />\n";
        $password_form.="</td>\n";
        $password_form.="</tr>\n";
        $password_form.="</table>\n";
        $password_form.="</form>\n";

    }

} // If Password
echo "2";
// Dont allow submit if $password_form has been populated
If(($_POST['submit']==true) AND ($password_form=="")) {
echo "3";
    //Tally the size of all the files uploaded, check if it's over the ammount. 
    If(array_sum($_FILES['file']['size']) > $max_combined_size*5000) {

        $error.="<b>FAILED:</b> All Files <b>REASON:</b> Combined file size is to large.<br />";

    // Loop though, verify and upload files.
    } Else {
echo "4";
        // Loop through all the files.
        For($i=0; $i <= $file_uploads-1; $i++) {

            // If a file actually exists in this key
            If($_FILES['file']['name'][$i]) {
echo "5";
                //Get the file extension
                $file_ext[$i]=get_ext($_FILES['file']['name'][$i]);

                // Randomize file names
                If($random_name){
                    $file_name[$i]=time()+rand(0,100000);
                } Else {
                    $file_name[$i]=cln_file_name($_FILES['file']['name'][$i]);
                }
    echo "6";
                // Check for blank file name
                If(str_replace(" ", "", $file_name[$i])=="") {

                    $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> Blank file name detected.<br />";

                //Check if the file type uploaded is a valid file type. 
                }   ElseIf(!in_array($file_ext[$i], $allow_types)) {

                    $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> Invalide file type.<br />";

                //Check the size of each file
                } Elseif($_FILES['file']['size'][$i] > ($max_file_size*1024)) {

                    $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> File to large.<br />";

                // Check if the file already exists on the server..
                } Elseif(file_exists($folder.$file_name[$i].".".$file_ext[$i])) {

                    $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> File already exists.<br />";

                } Else {

                    If(move_uploaded_file($_FILES['file']['tmp_name'][$i],$folder.$file_name[$i].".".$file_ext[$i])) {



                        $success.="<b>SUCCESS:</b> ".$_FILES['file']['name'][$i]."<br />";
                        $success.="<b>URL:</b> <a href=\"".$full_url.$file_name[$i].".".$file_ext[$i]."\" target=\"_blank\">".$full_url.$file_name[$i].".".$file_ext[$i]."</a><br /><br />";

                            include_once( 'class/class.upload.php' );
    if(isset($_POST['upload'])){
        $filname=$_FILES['file_name'];
        $handle = new upload($filname);
        $handle->allowed = array('image/*');
        if($handle->uploaded){
            $handle->image_border          = 5;   // defining border width
            $handle->image_border_color    = '#000'; // defining border color
            $handle->image_watermark = 'badge.png';  // watermark image src
            $handle->image_watermark_position = 'BR'; // watermark image position again "B" for bottom and so on.
            $handle->image_resize         = true;   // making resize function to true
            $handle->image_x              = 160;    // making width to 160px
            $handle->image_y              = 160;    // making hight to 160px
            $handle->process('uploads/');
            if ($handle->processed) {


                    } Else {
                        $error.="<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> General upload failure.<br />";
                    }

                }

            } // If Files

        } // For

    } // Else Total Size

    If(($error=="") AND ($success=="")) {
        $error.="<b>FAILED:</b> No files selected<br />";
    }

    $display_message=$success.$error;

and this is what i'm trying to insert:

  include_once( 'class/class.upload.php' );
    if(isset($_POST['upload'])){
        $filname=$_FILES['file_name'];
        $handle = new upload($filname);
        $handle->allowed = array('image/*');
        if($handle->uploaded){
            $handle->image_border          = 5;   // defining border width
            $handle->image_border_color    = '#000'; // defining border color
            $handle->image_watermark = 'badge.png';  // watermark image src
            $handle->image_watermark_position = 'BR'; // watermark image position again "B" for bottom and so on.
            $handle->image_resize         = true;   // making resize function to true
            $handle->image_x              = 160;    // making width to 160px
            $handle->image_y              = 160;    // making hight to 160px
            $handle->process('uploads/');
            if ($handle->processed) {

you can see it in the code (near the bottom), but I think it is placed the wrong place.
I hope you understand what I meen and can help me.

Thank you :)

3
Contributors
13
Replies
14
Views
5 Years
Discussion Span
Last Post by kischi
0

This usually related to unbalanced braces { and }. Sorry, not going to wade through all that! If your code is correctly indented it should be straightforward to spot. You could go through the code and try to add comments where you match start and end levels. SOme IDEs can help with this with dropdown lines linking matched tabs (I think Notepad++ does this). Alternatively comment out /* */ control blocks to try and isolate the section concerned - BUT this can throw up other errors.

Edited by diafol

0

Yeah ok, I got that part working, but now I'm trying to get an if sentence working.
I want to say:

If the size in below 5000kb do this else echo this.

But I don't think I'm doing it right.

I get this error:

Parse error: syntax error, unexpected '{' in /home/www/wearecrunch.dk/gammelsjuf/somefile.php on line 50

that is where the if sentence starts.

Do you know what i'm doing wrong, my code looks like this.

<?php
if(($_FILES['file']['size'][$i] > ($max_file_size*5000)) 
{
    include_once( 'class/class.upload.php' );
    if(isset($_POST['upload'])){
        $filname=$_FILES['file_name'];
        $handle = new upload($filname);
        $handle->allowed = array('image/*');
        if($handle->uploaded){
            $handle->image_border          = 5;   // defining border width
            $handle->image_border_color    = '#000'; // defining border color
            $handle->image_watermark = 'badge.png';  // watermark image src
            $handle->image_watermark_position = 'BR'; // watermark image position again "B" for bottom and so on.
            $handle->image_resize         = true;   // making resize function to true
            $handle->image_x              = 160;    // making width to 160px
            $handle->image_y              = 160;    // making hight to 160px
            $handle->process('uploads/');
            if ($handle->processed) {

                //$message = '<div class="center"><p>Border color #F58462 added successfully</p><img src="uploads/'.$handle->file_dst_name.'" alt="" /></div>';





                 //*** Uniqid Session ***//
    $strSid = md5(uniqid(time()));
    $to = $_POST['mail'];
    $from = 'adamkischi@gmail.com'; 
    $subject = 'the subject';
    $headers = 'From: '.$from. "\r\n" . 'Reply-To: '.$from. "\r\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
    $headers .= "This is a multi-part message in MIME format.\n";
    $headers .= "--".$strSid."\n";
    $headers .= "Content-type: text/html; charset=utf-8\n";
    $headers .= "Content-Transfer-Encoding: 7bit\n\n";
    if($_FILES["file_name"]["name"] != "") {
    $strFilesName = $_FILES["file_name"]["name"];
    $strContent = chunk_split(base64_encode(file_get_contents('uploads/'.$strFilesName)));
    $headers .= "--".$strSid."\n";
    $headers .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
    $headers .= "Content-Transfer-Encoding: base64\n";
    $headers .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
    $headers .= $strContent."\n\n";
    }
    $flgSend = @mail($to, $subject, $message, $headers); // @ = No Show Error //
   if($flgSend){
echo "<font color='black'>Mail send completed</font>";
$tmpfile = 'uploads/'.$strFilesName;
// http://php.net/manual/en/function.file-exists.php
if(file_exists($tmpfile)) {
// http://php.net/manual/en/function.unlink.php
unlink($tmpfile);
}
}

            }
        }
    }
}
else {
echo "The file is too large";
}
?>
0

Yeah I know the error is this { but why?

And the link you gave me to the other thread:

I didn't get that, that's why I wrote the last post, but didn't get a reply, now the problem is my if sentence isn't it? or am I completely on the wrong track?

thx

0

Yeah ok, so I deleted the bracket and now I get this error:

Parse error: syntax error, unexpected T_INCLUDE_ONCE in /home/www/wearecrunch.dk/gammelsjuf/somefile.php on line 51

I downloaded the file, but there are alot of files, and I wouldn't know how to implement the code I want in those files and in witch one.

so bottom line, the thing that works is that when a file is uploaded it creates a watermark on the file and sends the uploaded picture to the typed email.

and I just want to validate that the file uploaded does not exceed the max file size.
Can't I do that with a simple if sentence like I am trying?

The other files looks really complicated, and would probably end up using much more time with that than if I could do it with an if sentence.

So isn't it possible to do it with an if sentence like i'm trying to do?

I hope you understand my dilemma, thank's for your help.

0

@kischi

Yeah ok, so I deleted the bracket and now I get this error:

Parse error: syntax error, unexpected T_INCLUDE_ONCE in /home/www/wearecrunch.dk/gammelsjuf/somefile.php on line 51

I downloaded the file, but there are alot of files, and I wouldn't know how to implement the code I want in those files and in witch one.

so bottom line, the thing that works is that when a file is uploaded it creates a watermark on the file and sends the uploaded picture to the typed email.

and I just want to validate that the file uploaded does not exceed the max file size.
Can't I do that with a simple if sentence like I am trying?

The other files looks really complicated, and would probably end up using much more time with that than if I could do it with an if sentence.

So isn't it possible to do it with an if sentence like i'm trying to do?

I hope you understand my dilemma, thank's for your help.

Did you write this script at all? The purpose of the link for you to download the file and take it a part. I mean it seems you are not trying to solve the issue. You're just waiting for someone to do the work for you. So I can't help you anymore.

0

I am sorry, but i'm trying. but the file I downloaded. I don't even know what file I should mess with, there are so many different files in the folder that I downloaded.

And it also seems like the file I downloaded is in jquery, now i'm trying to do it directly in php, because it seems easyer then taking 10 different files apart and finding out what code from that I can use.

But if there is no way to check it with an if sentence I guess i'll look through all the files to see if I can find what I need and then put it in my code.

But thank you for your help.
It was really not my intention to make you write the code for me, I just don't even know if i'm on the right track.

I'm sorry

0

@kischi

Where did you get this code?

The reason why I ask is that you can't get that much error after error!

0

@kischi

Did you read the instructions carefully?

Did you installed Php GD library ?

<?php echo php_info(); ?>

Did you enabled php.ini look for the line "extension=php_gd2.dll"?

Did you uncomment the following line by removing the semi-colon on the front:

    <?php
        if(isset($message)){
            echo $message;
        }
    ?>

If you still have issue I would suggested leave a comment to the Arthur!

0

yeah and the whole thing works fine, it's only when I try to validate for the file size that it comes up with errors, that's why i'm pretty sure it has nothing to do with that code.

It's just me that can't figure out how to validate for the file size.

But otherwise the code works fine if I choose not to validate.

unless ofcourse the file exceeds 2 mb then it won't upload and send the email it will just redirect to a blank page

0

Now I finally got it to work.
I could just make an else statement in my php code.

So if the file is not uploadet it will echo that the file is too large.

But thank you for your help :D

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.