SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php syntax needing quotes ? or brackets?

    I'm using the following bit of code and have the default value of one of the form item "pathtest1" to default to the value of a record from a database recordset. But when I try it live the form shows
    ('col19')
    instead of the actual value. I'm sure it has to do with the single quotes or double quotes missing, but I'm quite new to php so I'm not sure what's up.



    PHP Code:
    <?php
    function display_upload_form()
    {
    echo <<<DISPLAY_UPLOAD_FORM


    <form method="post" action="
    {$_SERVER['PHP_SELF']}" enctype="multipart/form-data">
         <table width="400" border="0" cellpadding="0" cellspacing="0">
               <tr class="cellbackground1">
                 <td width="107"><span class="apptext">Select Document</span></td>
                 <td width="293"><input type="file" name="myfile" tabindex="1" />
                   <input type="hidden" name="execute" value="1" />
                   <input name="recordid41" type="text" id="recordid41" value=
    {$_GET['recordid41']}>
                   <input name="recordid42" type="text" id="recordid42" value=
    {$_GET['recordid42']}>
                   <input name="pathtest1" type="text" id="pathtest1" value=
    $Recordset1->Fields('col19')></td>
               </tr>
               <tr class="cellbackground1">
                 <td>&nbsp;</td>
                 <td><input type="submit" value="Upload File" tabindex="2" /></td>
               </tr>
               <tr class="cellbackground1">
                 <td>&nbsp;</td>
                 <td>&nbsp;</td>
               </tr>
               <tr class="cellbackground1">
                 <td>&nbsp;</td>
                 <td>&nbsp;</td>
               </tr>
             </table>
                    </form>

    DISPLAY_UPLOAD_FORM;
    }

    // File Upload ****************************************************************

    function execute_upload()
    {
        
    //$pathtodocs=$Recordset1->Fields('col19');
        // root path
        
    $path $_POST['pathtest1'];
        
    // root path (this was the original code)
        //$path = $_SERVER['DOCUMENT_ROOT'];
        //$path = $pathtodocs;
        
        // upload directory. path will originate from root.
        
    $dirname '/docs/'.$_POST['recordid41'];

        
    // permission settings for newly created folders
        
    $chmod 0755;

        
    // create file vars to make things easier to read.
        //$filename = $_FILES['myfile']['name']; (this was in the original)
        
    $filename $_POST['recordid42'].".txt";
        
    $filesize $_FILES['myfile']['size'];
        
    $filetype $_FILES['myfile']['type'];
        
    $file_tmp $_FILES['myfile']['tmp_name'];
        
    $file_err $_FILES['myfile']['error'];
        
    $file_ext strrchr($filename'.');

        
    // check if user actually put something in the file input field.
        
    if (($file_err == 0) && ($filesize != 0))
        {
            
    // Check extension.
            
    if (!$file_ext)
            {
                
    unlink($file_tmp);
                die(
    'File must have an extension.');
            }

            
    // extra check to prevent file attacks.
            
    if (is_uploaded_file($file_tmp))
            {
                
    /*
                * check if the directory exists
                * if it doesnt exist, make the directory
                */
                
    $dir $path $dirname;

                if (!
    is_dir($dir))
                {
                    
    $dir explode('/'$dirname);

                    foreach (
    $dir as $sub_dir)
                    {
                        
    $path .= '/' $sub_dir;
                        if (!
    is_dir($path))
                        {
                            if (!
    mkdir($path$chmod))
                            {
                                
    unlink($file_tmp);
                                die(
    '<strong>Error:</strong> Directory does not exist and was unable to be created.');
                            }
                        }
                    }
                }

                
    /*
                * copy the file from the temporary upload directory
                * to its final detination.
                */
                
    if (@move_uploaded_file($file_tmp$dir '/' $filename))
                {
                    
    // success(this was the original lines I changed below)!
                    // echo "
                    // <p>Successful Upload!</p>
                    // <p><strong>View File:</strong> <a href=\"$dirname/$filename\">$filename</a></p>
                    // ";
                    // success!
                    
    echo '<a href="190.php?recordid41='.$_POST['recordid41'].'" class="links">Successful Upload! Return</a>';
                }
                else
                {
                    
    // error moving file. check file permissions.
                    
    unlink($file_tmp);
                    echo 
    '<strong>Error:</strong> Unable to move file to designated directory.';
                }
            }
            else
            {
                
    // file seems suspicious... delete file and error out.
                
    unlink($file_tmp);
                echo 
    '<strong>Error:</strong> File does not appear to be a valid upload. Could be a file attack.';
            }
        }
        else
        {
            
    // Kill temp file, if any, and display error.
            
    if ($file_tmp != '')
            {
                
    unlink($file_tmp);
            }

            switch (
    $file_err)
            {
                case 
    '0':
                    echo 
    'That is not a valid file. 0 byte length.';
                    break;

                case 
    '1':
                    echo 
    'This file, at ' $filesize ' bytes, exceeds the maximum allowed file size as set in <em>php.ini</em>. '.
                    
    'Please contact your system admin.';
                    break;

                case 
    '2':
                    echo 
    'This file exceeds the maximum file size specified in your HTML form.';
                    break;

                case 
    '3':
                    echo 
    'File was only partially uploaded. This could be the result of your connection '.
                    
    'being dropped in the middle of the upload.';

                case 
    '4':
                    echo 
    'You did not upload anything... Please go back and select a file to upload.';
                    break;
            }
        }
    }

    // Logic Code *****************************************************************

    if (isset($_POST['execute']))
    {
        
    execute_upload();
    }
    else
    {
        
    display_upload_form();
    }


    ?>

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    again try surrounding it by {}
    {$Recordset1->Fields('col19')}
    ---------------------------
    Errors = Improved Programming.
    My Site

  3. #3
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the suggestion. I gave that a try but it gives this error and refers to the line of code containing {$Recordset1->Fields('col19')}

    Parse error: parse error, expecting `'}''

  4. #4
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i can't think of anything else right now.
    i would suggest you do this
    PHP Code:
    $col19 $Recordset1->Fields('col19');
    echo <<<DISPLAY_UPLOAD_FORM
    blah .blah. blah
    DISPLAY_UPLOAD_FORM; 
    where you were putting $Recordset1->Fields('col19') NOW PUT $col19
    give it a try
    ---------------------------
    Errors = Improved Programming.
    My Site


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •