mardi 4 août 2015

kcfinder have upload directory selected through URL

Problem: As found in kcfinder's definition I am using this link to open kcfinder:

window.open('/kcfinder/browse.php?type=files&dir=files/public&subDir=/PO/'+editId, 'kcfinder_textbox',
            ', width=800, height=600');

In here, I have modified the URL to also include the subdirectory path so that the URL becomes something like this http://ift.tt/1VZ7aBx .

The subDir part has the directory name to be set to (and created if not exists). In the config.php I already have a directory set to be the root. So if the subDir is provided it will create the subDir inside the root of config.php. Now I would want this subDir to be the new root directory for kcfinder.

So for example if my uploadURL in the config is /var/www/html/web/upload/ the new root for the above URL will become /var/www/html/web/upload/PO/200836/.

Attempt: So far I have been able to successfully create the directory /var/www/html/web/upload/PO/200836/ for the above URL (or any URL) provided. However, the root in kcfinder is still set to /var/www/html/web/upload/. So when I open the kcfinder, the directory gets created internally but the root is still set to the original root from config.php.

I added the following lines to change my root directory to the sub directory I pass through URL:

$this->config["uploadURL"] .= $_GET['subDir'];
$this->config["uploadDir"] .= $_GET['subDir'];
$this->typeDir = $this->config["uploadDir"] ."/files";
$this->typeURL = $this->config["uploadURL"] ."/files";

I have also raised this as an issue on github but no response from there yet. I am assuming the only change I need to do is set the root directory to display to the new directory being created but I am not sure where I am supposed to do this.

Is there a workaround for this?

PS: I am also open to any other web file manager PHP/jQuery solutions which has a way to do this. Using symfony as the framework.



via Chebli Mohamed

Composer, class within my package is not being autoloaded in application using it

I'm creating a module which I will include in several projects. However, in a project that uses the module, the autoloader doesn't seem to include the class in the module.

The module structure (etc) is as follows:

Directory structure in the git repository:

/
/composer.json
/src/
/src/EbayAPI.php

composer.json:

{
    "name": "jodes/ebay-api",
    "autoload": {
        "psr-4" : {
            "Jodes\\EbayAPI\\" : "src"
        }
    }
}

EbayAPI.php:

<?php
namespace Jodes;
class EbayAPI {}

And the application I'm trying to include it in has the following:

composer.json:

{
    "require": {
        "behat/behat": "@stable",
        ....other requirements in here...
        "jodes/ebay-api": "dev-master"
        },
    "config": {
        "bin-dir": "bin/"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "http://ift.tt/1P3M0gX"
        }
    ]
}    

And the php file that wants to use my package via the autoloader is:

<?php

use Jodes\EbayAPI;
require_once 'vendor/autoload.php';

class HelloWorld {
    public function __construct(){
        $ebay = new EbayAPI();
    }
}

The error I get is

Fatal error: Class 'Jodes\EbayAPI' not found

What am I doing wrong? Thanks



via Chebli Mohamed

HTML/PHP selecting a value from dropdown menu and retrieving the associated row and output all the data from that row

Its a bit hard to express what I want to do but let me give it a shot.

First of all I have a database with a table. One of the columns from that table I will be showing in a select dropdown menu in HTML, to be more precise: this outputs the column 'name' in the dropbown menu:

<?php
$query = mysql_query("SELECT name from table");

echo "<select name='select1'>";

while ($row = mysql_fetch_array($query))
{
echo "<option value'" . $row['name'] ."'>" . $row['name] . "</option>;
}
echo "</select>";
?>

Then when a value is selected in that dropdown, that value needs to be saved in a variable.

if (isset($_POST['button']))
{
$select = $_POST['select1'];
}

As last bit, the value in variable $select needs to be used to make a SELECT query. I want to use that variable in the SELECT statement to look for the corresponding row (in the same table) that is related to the value in the dropdown menu and pick a column and output that value to a textbox or checkbox, depending on as what the value needs to be outputted.

Example:

TABLE

      id - name - street - number - ...
row 1: 0 - test1 - teststreet1 - 1 - ...
row 2: 1 - test2 - teststreet2 - 2 - ...
row 3: 2 - test3 - tesstreett3 - 3 - ...

1) I select test2 from the dropdown menu (dropdown menu is filled with the column name from database)

2) test2 is saved as a variable in $name

3) select query searches for value of street column where $name = test2

SELECT street from table where ?
row 2: 1 - test2 - tesstreett2 - 2 - ...

So I want teststreet2 from street to be outputted in a textbox

<input type='text' value='?'>

I need help with the select query or how to call this.

Thanks in advance and taking time to read this!

Kind Regards



via Chebli Mohamed

PHP, prevent javascript from running

I am making a website where people will publish an article. I make them write their article in a textarea, but I don't want them to add javascript, php or any other langage than html to prevent XSS or SQL injections.

How can I do this?



via Chebli Mohamed

How to push only validation error messages into an array using Laravel

I have a validator, it has error messages, and my goal is to get only error messages with the field names.

$validator = Validator::make(
   array(
      'firstField' => Input::get('firstFieldName');
      'secondField' => Input::get('secondFieldName');
   ),
   array(
      'firstField' => 'required';
      'secondField' => 'required';
   )
);

if($validator->fails()){
   return $validator->messages();
}

So, this piece of code is returning some values to my js file as following

function getErrorMessages(){
   //Some UI functions
   var myDiv = document.getElementById('messageDivID');
   $.post('validationRoute', function(returedValidatorMessageData)){
      for(var a in returedValidatorMessageData){
         myDiv.innerHTML = myDiv.value + a;
      }
   }
}

Problem is, the only values i get from post request is like firstField secondField but i'd like to get like firstField is required message. What would be the easiest way ?

Thanks in advance.



via Chebli Mohamed

How to match any characters without space and don't array usefull things

How to search all characters without space and optimize speed of my script by don't adding LTEXT, PUSHBUTTON etc to the array.

My pattern:

$pattern = '/(LTEXT|PUSHBUTTON|CAPTION|GROUPBOX|RTEXT|MENUITEM|[0-9]+|IDS_.+|STRING_.+) .*"(.+)".*\R?/';

To be more specific: searching chars without characters must be in this place of code: "(.+)"

Input:

IDS_NO_SUCH_FILE "FIND: %s: Plik nie został znaleziony\n"
LTEXT_BLANK " "
0 "Some text"
1 " Some text "

Output

FIND: %s: Plik nie został znaleziony\n
Some text
 Some text 



via Chebli Mohamed

build an array of mysql query?

Could someone please let me know how I can create an array from the MYSQL query?

The array should look like this:

<?php
$testLocs = array(
    '1' => array( 'info' => '1. New Random info and new position', 'lat' => 45345345, 'lng' => 44.9634 ),
    '2' => array( 'ino'  => '1. New Random info and new position', 'lat' => 686788787, 'lng' => 188.9634),
    '3' => array( 'info' => '1. New Random info and new position', 'lat' => 88888, 'lng' => 144.9634),
    '4' => array( 'info' => '1. New Random info and new position', 'lat' => 666666, 'lng' => 144.964 )
);
echo json_encode($testLocs);
exit();
?>

where the Texts for info and numbers for lat and lng are mysql $rows.

Any help would be appreciated.



via Chebli Mohamed