cereal 1,524 Nearly a Senior Poster Featured Poster

image_type_to_extension() will work because it is not based on the file extension, it read the mime type of the file, you can achieve the same result by using finfo: http://www.php.net/manual/en/function.finfo-file.php

And now it makes perfect sense, I wasn't sure about some of those methods, your explanation clarifies my doubts. Try this:

# last part of getImagefile() ...

    } else {

        $file = $this->params['images_dir'].$image;

        //
        // if the image is a regular file
        //

        if(is_file($file.'.jpg') || is_file($file.'.GIF'))
        {
            $finfo = finfo_open(FILEINFO_MIME_TYPE);
            switch(finfo_file($finfo, $file))
            {
                case 'image/jpeg':
                    $file = $file . '.jpg';
                    break;
                case 'image/gif':
                    $file = $file . '.GIF';
                    break;
            }
        }
    }

    return $file;
}

It's just an example but it should work fine. Just pay attention to uppercase, if you're using a linux box image.GIF will be considered different from image.gif. In practice my suggestion is the same solution of yours, the only difference is that I'm not applying $this->params['images_dir'] and DIR_IMAGE togheter. Have you checked the logs of the server to see if there are undefined paths?

cereal 1,524 Nearly a Senior Poster Featured Poster

Looking at the code you could get your result just by replacing:

return $file;

With:

return $file . image_type_to_extension($image_info[2]);

But you should already get this, since it is used between line 61 and 80.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

late reply, but it can still be useful for people searching. At line 19 you wrote:

$link = 'http://search.twitter.com/search.rss?geocode=' . $lat . $sp . $long . $sp . $radius;

which it may be valid in API 1.0, but in Twitter API 1.1 the link changes to:

$link = "https://api.twitter.com/1.1/search/tweets.json?geocode=$lat,$long,$radius&q=pizza";

The q parameter is required, so it cannot be omitted. Also you have to append mi (mile) or km (kilometer) to the radius variable.

More information: https://dev.twitter.com/docs/api/1.1/get/search/tweets

cereal 1,524 Nearly a Senior Poster Featured Poster

You can use find or tree for example, or mc to use something interactive. But if you explain why you cannot use ls maybe we can suggest the best solution for you.

cereal 1,524 Nearly a Senior Poster Featured Poster

Line 8, change it to:

if($db = sqlite_open('./ET'))

I suppose ET is the name of the database file.

cereal 1,524 Nearly a Senior Poster Featured Poster

Currently it runs twice. Change line 10 to:

$sent = mail($email, $subject, $message, $headers);

And line 13 to:

if($sent === TRUE)
{
    # success
}
else
{
    # failure
}
BadManSam commented: Ok, Thank You. It now is sent once. +1
cereal 1,524 Nearly a Senior Poster Featured Poster

Also, are these values encoded? For example hello%20

In this case you can run:

update table_name set field_name = trim(BOTH '%' FROM field_name);

This will remove just % if you have other codes, as example an encoded empty space %20, you have to change it to:

update table_name set field_name = trim(BOTH '%20' FROM field_name);
cereal 1,524 Nearly a Senior Poster Featured Poster

Show the query that you use to select.

Also, to remove white space use trim(). This function exists in PHP and MySQL, so when you insert from PHP you can just do something like this:

$var = trim($var);

if you want to fix the rows in your table, you can run an update query:

update table_name set field_name = trim(field_name);

This will remove leading and trailing spaces: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_trim

cereal 1,524 Nearly a Senior Poster Featured Poster

Basically when you register the data sent by the registrant, you have to use the E-mail library:

If you're still in doubt show your code.

cereal 1,524 Nearly a Senior Poster Featured Poster

It seems a method of the class FGMembersite() to start a database connection, check in ./include/fg_membersite.php for more details.

cereal 1,524 Nearly a Senior Poster Featured Poster

You will probably need to perform a subquery in order to get the results of the cases, and then sum the results in the main query, this should work:

SELECT s.soldby AS 'sales person', SUM(sub.packages) AS packages, SUM(sub.sales) AS total FROM sales AS s, (SELECT id, soldby, CASE WHEN package = 1 THEN count(package)*5 WHEN package = 6 THEN COUNT(package)*25 WHEN package = 25 THEN COUNT(package)*100 END AS sales, SUM(package) AS packages FROM sales GROUP BY soldby, package) AS sub WHERE s.id = sub.id GROUP BY s.soldby;

Reference table for this example:

CREATE TABLE `sales` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `soldby` varchar(255) DEFAULT NULL,
  `package` tinyint(3) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8

Reference link: http://dev.mysql.com/doc/refman/5.5/en/control-flow-functions.html

But I'm wondering if there is a better method to achieve this. Maybe a procedure?

cereal 1,524 Nearly a Senior Poster Featured Poster

Yes, News is a rename from Codeigniter folder.

It is not clear to me. So you have a setup similar to this:

/
/News/
/News/index.php
/News/system/
/News/application/

Correct? Be aware that News and news are different paths for the system. So if the name of the directory is all lower case your link will be:

http://localhost/news/index.php/pages/create
cereal 1,524 Nearly a Senior Poster Featured Poster

Congrats! :)

JorgeM commented: thanks cereal +0
cereal 1,524 Nearly a Senior Poster Featured Poster

News is a subdirectory? CodeIgniter is installed there?

Try: http://localhost/index.php/pages/create

cereal 1,524 Nearly a Senior Poster Featured Poster

Anyway, I'm realizing I wrote a wrong example, sorry, I intended:

mysql_query($query) or die(mysql_error());

bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Add mysql_error() to your execution:

mysql_query($query) or die(mysql_query())

This will output the error, it should help you to solve the problem.

cereal 1,524 Nearly a Senior Poster Featured Poster

Intended font is supposed to be 16px at 100% so I think it's something on your end??

Confirmed, the problem was on my end, I was using Google Chrome 17.* on Ubuntu 12.04, my system gave me this as stable version, by adding another source I was able to upgrade to version 28, now it's all nice and shiny.

Solution steps:

  1. add new source:

    wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
    
  2. add the key:

    sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
    
  3. update:

    sudo apt-get update
    

After the update the system will prompt for the installation of the latest stable version. Otherwise search it by typing: apt-cache search google-chrome

As note: Chrome 23.* and higher displays fine.

Thank you for your time Dani! :)

cereal 1,524 Nearly a Senior Poster Featured Poster

Do you get any other specific error apart that? Have you checked CakePHP log files?

At line 10 of your script you wrote:

$uploadFolder = WWW_ROOT . 'files' .DS.$filename;

What's the value of WWW_ROOT? Check if there is a slash at the end, otherwise add DS:

$uploadFolder = WWW_ROOT . DS . 'files' . DS . $filename;

Also check if files directory is writable.

cereal 1,524 Nearly a Senior Poster Featured Poster

cereal, are you using any third party extensions or plugins of any kind??

yup, but I switched them off two hours ago and nothing changed.

I think the problem is given by the size of the fonts, if I click on CTRL+- (i.e. reduce) everything goes in place and looks fine, when I click on CTRL+0 (back to normal) the problem appears, but if I reload the page, it doesn't happen anymore, very strange.

The issue happens also in forum and profile pages, here are few screenshots:

c752533a227d9730a7c417fa1f1d6821

5405c74f561508cef8eb82a4b353b629

Default zoom is 100%. Default font size is medium (16px), maybe depends on this. I will try with another linux box as soon as I can, maybe it's just my setup. I will let you know.

cereal 1,524 Nearly a Senior Poster Featured Poster

So, a part the name of the function that is wrong upolad() instead of upload() what's the problem with your script?

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, my issue is still valid: yesterday after cleaning the cache it disappeared but, now, I'm experiencing it again. Now it's totally random.

Also in related topics (right box) I get articles from restricted areas, as this link which is in Moderators forum:

http://www.daniweb.com/community-center/daniweb-community-feedback/moderators-place/threads/423718/new-mods-thread

cereal 1,524 Nearly a Senior Poster Featured Poster

I think my problem depended on browser cache, after choosing to clear it completely seems to work fine. Thanks for your attention :)

cereal 1,524 Nearly a Senior Poster Featured Poster

I'm not sure why this happens, but increment and decrement methods seems to be buggy: the library is still using a deprecated function to retrieve results: memcached_fetch instead of memcached_fetch_result. On github there are few pull request that solves most of the open issues with the increment function, but it seems to be no activity from the authors.

So, you could create your own branch, merge the pull request and recompile the library on your own.

Reference:

cereal 1,524 Nearly a Senior Poster Featured Poster

@szabizs

You don't need to add ALL to retrieve complete entries from those arrays, just:

print_r($this->input->get());

Same applies to post() method.

Szabi Zsoldos commented: thanks :) +4
cereal 1,524 Nearly a Senior Poster Featured Poster

Hello there!

I'm occasionally experiencing some problems with the new layout:

Primarly the text of the post overflows outside the right border, and if I use inline code the previous word is covered. I'm attaching an image with the different problems. In the case of the inline code the word under the label is using.

This happens when I open a thread for the first time, reloading it fixes the layout, but if I quit the page and go back I experience the same problem.

6e4d4007844cd9634bcc73e0a80bf580

Reference thread for above screenshot:

http://www.daniweb.com/web-development/php/threads/460877/accessing-data-outside-of-this-request-data-using-the-cakephp-way

Current UserAgent:

Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.78 Safari/535.11

Works fine on Mozilla Firefox 23.0

cereal 1,524 Nearly a Senior Poster Featured Poster

It means "return only the first row of the result set", it's like using limit 1 in a query. If you open the link that I pasted above, you can access the documentation of this method.

cereal 1,524 Nearly a Senior Poster Featured Poster

Have you tried the Model::find() method? As example:

$row = $this->Test->find('first', array(
    'conditions' => array('Test.username' => 'jimmorrison')
));

print_r($row);

More info: http://book.cakephp.org/2.0/en/models/retrieving-your-data.html

cereal 1,524 Nearly a Senior Poster Featured Poster

If you want to use a link identifier as second paramenter you should remove the closing quote, so from this:

$email = mysql_query("myquery, $connectmysql");

to this:

$email = mysql_query("myquery", $connectmysql);

Also you have to use mysql_fetch_* functions before you can access the resource results:

Consider also the Warning on the top of each of those pages and move to PDO or MySQLi library.

cereal 1,524 Nearly a Senior Poster Featured Poster

To strictly reply to your question you can use the physical name of the file, you get this from $_FILES array, for example:

$this->Html->link($_FILES['fieldname']['name'], '/path/'.$_FILES['fieldname']['name']);

But consider to go through these few steps before printing anything temporary, because you could allow the execution of a malicious script:

  1. check if file is allowed, for example: jpg, pdf, zip
  2. rename it, to avoid accidentals rewrites of existing files
  3. save the file name somewhere, for example into a database

Then you can query the database to retrieve the file list and loop them to build an output. Otherwise you can scan the directory in which the files are saved. In any case you have to do at least the first two steps.

Check this for more information: https://www.owasp.org/index.php/Unrestricted_File_Upload

cereal 1,524 Nearly a Senior Poster Featured Poster

Works fine for me. Probably it depends by your DNS, try to run this from a terminal:

dig www.kovaidonbosco.com

and then:

dig @8.8.8.8 www.kovaidonbosco.com

and:

dig www.kovaidonbosco.com.cdn.cloudflare.net

In the first two cases, if cloudflare is off, you should get your server IP. For more information check: https://support.cloudflare.com/entries/22066298-Hosting-Partner-Troubleshooting

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, standing to CakePHP documentation (not sure about the version you are using) Html->link() method expects at least two parameters: title and url.

HtmlHelper::link(string $title, mixed $url = null, array $options = array(), string $confirmMessage = false)

So your code $this->Html->link($pod['Pod']['pod']) should change to something like:

$this->Html->link('Name of the File', '/path/'.$pod['Pod']['pod']);

Reference: http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::link

cereal 1,524 Nearly a Senior Poster Featured Poster

Are you also storing the path in which the file is saved?

cereal 1,524 Nearly a Senior Poster Featured Poster

Not sure if this helps, I checked the source of thr_lock.c as suggested here: http://dev.mysql.com/doc/refman/5.5/en/table-locking.html

It seems this depends on max_write_lock_count, once reached the limit, all the pending read locks are released. But it appears possible to change the behaviour of the queue system. This is what is written in the comments:

The current lock types are:
TL_READ         # Low priority read
TL_READ_WITH_SHARED_LOCKS
TL_READ_HIGH_PRIORITY   # High priority read
TL_READ_NO_INSERT   # Read without concurrent inserts
TL_WRITE_ALLOW_WRITE    # Write lock that allows other writers
TL_WRITE_CONCURRENT_INSERT
            # Insert that can be mixed when selects
TL_WRITE_DELAYED    # Used by delayed insert
            # Allows lower locks to take over
TL_WRITE_LOW_PRIORITY   # Low priority write
TL_WRITE        # High priority write
TL_WRITE_ONLY       # High priority write
            # Abort all new lock request with an error

Locks are prioritized according to:
WRITE_ALLOW_WRITE, WRITE_CONCURRENT_INSERT, WRITE_DELAYED,
WRITE_LOW_PRIORITY, READ, WRITE, READ_HIGH_PRIORITY and WRITE_ONLY

Locks in the same privilege level are scheduled in first-in-first-out order.

Lock types matches SELECT, INSERT, etc. modes:

  • SELECT [HIGH_PRIORITY]
  • INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY]
  • INSERT [LOW_PRIORITY | HIGH_PRIORITY] SELECT
  • UPDATE [LOW_PRIORITY]

The prioritized list seems to be in ascending order. So, according to this list, there's an order also in the write queue, where WRITE_ONLY is the higher privilege, however you can change the priority of a write lock to a lower level, check thr_downgrade_write_lock() starting at line ~1256. And check line ~682 for exceptions.

If you are in Debian/Ubuntu you can get the source by typing:

cereal 1,524 Nearly a Senior Poster Featured Poster

It depends on remote websites, something like facebook allows remote logins only with OAuth methods, this means a user of facebook doesn't need to share his own credentials (as the password) with your service, check this for more information: https://developers.facebook.com/docs/facebook-login/

In other cases (HTTP Basic Authentication & Co.) you can just send something like this username:password@website.tld to the correct resource and gain access.

Or you have to send a POST request with appropriate values to the script that usually receives the data of the login form.

In most cases you will use the cURL library, so if you want to try check the documentation: http://php.net/manual/en/book.curl.php

If you still have doubts post your code, we will try to help.

cereal 1,524 Nearly a Senior Poster Featured Poster

Try to remove ['Post'] from the variables, for example: $post['title'] instead of $post['Post']['title'].

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok my previous suggestion was wrong, excuse me, this should solve your issue:

$hrs = array();
$i = 0;

foreach($postslist as $post)
{
    $hrs[$i][] = get_post_meta( $post->ID, 'Start',true );
    $hrs[$i][] = get_post_meta( $post->ID, 'End',true );
    $hrs[$i][] = get_post_meta( $post->ID, 'Name',true );
    $i++;
}

var_dump($hrs);

Otherwise on previous version you can use array_chunk():

print_r(array_chunk($hrs, 3));
cereal 1,524 Nearly a Senior Poster Featured Poster

Outside and before the foreach loop, otherwise both are restarted after each iteration, so:

$result = array();
$hrs = array();

foreach($postslist as $post)
{
    $hrs[] = get_post_meta( $post->ID, 'Start',true );
    $hrs[] = get_post_meta( $post->ID, 'End',true );
    $hrs[] = get_post_meta( $post->ID, 'Name',true );
}

$result[] = $hrs;
var_dump($result);
cereal 1,524 Nearly a Senior Poster Featured Poster

That loop will generate:

$hrs = array("2013-07-27 13:00", "2013-07-27 13:49", "cucu");

If you need a multidimensional array an easy solution is to start like this:

$result = array();
$hrs = array();

And after the loop:

$result[] = $hrs;
var_dump($result);

If you don't have other segments to add, i.e.:

$result = array(
    array("2013-07-27 13:00", "2013-07-27 13:49", "cucu"),
    array("2013-07-27 15:00", "2013-07-27 15:49", "hello"),
    array("2013-07-27 17:00", "2013-07-27 17:49", "abc"),
    );

you can probably use your current script and change the part of it that will use this output.

cereal 1,524 Nearly a Senior Poster Featured Poster

Try igbinary instead of serialize/unserialize, it is faster. Also you can try to store these objects to memory, through Memcached. Since session files will be written to disk you get high I/O activity and this, if session directory is in the same disk of the web server, can decrease performance.

In order to work with these tools you will need to install them in the server, in particular make sure to have a firewall enabled and to filter memcached ports, otherwise you will expose the daemon to everyone.

For more information check:

cereal 1,524 Nearly a Senior Poster Featured Poster
cereal 1,524 Nearly a Senior Poster Featured Poster

Many thanks, now it works fine :)

cereal 1,524 Nearly a Senior Poster Featured Poster

Hello,

I've an array with different type of values: int, null, strings, arrays. I'm trying to remove nulls and empty strings, but I want to save ints, even when it equals to zero, so I tried with array_filter(), by default it will remove 0, '' and null, but by applying a callback it's possible to apply own rules. So I made few tests, and I'm getting unexpected results. The switch method will remove null and 0, while the if statements will remove the empty string and null, as I wanted. Now, I can use the if statements, but I don't understand why there's this difference between the two methods, even by removing the breaks it won't change results.

Any ideas why this is happening?

<?php

$array = array(
    0,                      # int
    null,                   # null
    '',                     # empty string
    'hello',                # string
    array('world')          # array
    );

$r['original'] = $array;

$r['switch_method'] = array_filter($array, function($value) {
    switch($value)
    {
        case is_string($value):
            return ! empty($value);
            break;
        case is_int($value):
            return true;
            break;
        case is_null($value):
            return false;
            break;
        case is_array($value):
            return count($value);
            break;
        default:
            return false;

    }
});

$r['ifelseif_method'] = array_filter($array, function($value) {

    if(is_string($value))
    {
        return ! empty($value);
    }

    elseif(is_int($value))
    {
        return true;
    }

    elseif(is_array($value))
    {
        return true;
    }

    elseif(is_null($value))
    {
        return false;
    }

    else
    {
        return false;
    }

});

var_dump($r);
echo PHP_EOL;

This is the output:

array(3) {
  ["original"]=>
  array(5) {
    [0]=>
    int(0)
    [1]=>
    NULL
    [2]=>
    string(0) ""
    [3]=>
    string(5) "hello"
    [4]=>
    array(1) {
      [0]=>
      string(5) "world"
    }
  }
  ["switch_method"]=>
  array(3) {
    [2]=>
    string(0) "" …
cereal 1,524 Nearly a Senior Poster Featured Poster

Change this line:

$srclocation = $_SERVER['SERVER_NAME']."/includes/key.php";

With:

$srclocation = $_SERVER['DOCUMENT_ROOT']."/includes/key.php";

SERVER_NAME will return the domain name, not the path.

cereal 1,524 Nearly a Senior Poster Featured Poster

That means you are using FastCGI, you can also use echo PHP_SAPI;

cereal 1,524 Nearly a Senior Poster Featured Poster

If there aren't any NULL values you could use CONCAT(). For example you have a table like this:

create table posts(
    id auto_increment primary key not null,
    title varchar(255) not null,
    body text not null,
    created_at datetime not null,
    updated_at datetime not null
) engine = myisam default charset=utf8;

Now if you want to save the hash to the same table you can add a field hash:

alter table posts add hash varchar(40) not null;

And perform a query like this:

update posts set hash = sha1(concat(id, title, body, created_at, updated_at));

This will run the hash against all the rows.

You can change method and use ARCHIVE engine instead, you cannot modify the entries once inserted, nor you can delete them. So it depends on your goals. You can also save the hash to another table (with archive engine) which will work as logger, in this case you will need an ID as foreing key, the hash and the date of when the check was performed, so you can perform multiple checks and compare results.

As I wrote it depends on you, if you have to hash existing data you don't need to pull it to PHP, you can run the queries directly in a MySQL client, otherwise if you're inserting data through a form, you can process the hash before sending everything to the database.

Or you can create a trigger. There are many solutions.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

on line 59 change this:

$result=mysql_query($qry);

to:

$result=mysql_query($qry) or die(mysql_error());

This will display the details of the error, check if it helps to solve the problem, bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

No problem. For example because this will make the property (variable) available inside the extended classes:

class Mailer extends Action
{        
    public function send_mail()
    {
        $emailTo = $this->userinfo['email'];

        # ... other code here ...
    }
}

It will be more easy to deal with data between classes. Check these links for more information:

cereal 1,524 Nearly a Senior Poster Featured Poster

First, remove global $userInfo; from line 33, and set it as public/protected/private variable at the top of the class:

class Action
{
    public $userInfo;

So, at line 47 you can write:

$this->userInfo = $stmt->fetch_array(MYSQLI_ASSOC);
cereal 1,524 Nearly a Senior Poster Featured Poster

Not:

`autod.mark`

But:

`autod`.`mark`

Also at line 29 there is no space between mudel.id and $where values, so it will generate:

... INNER JOIN mudel ON autod.mudel = mudel.idWHERE`autod.mark`=7;

Which is wrong. To see the error in the query change this:

if(!$cmd){
    $response['err'] = "Tekkis viga andmete küsimisel!";
    $response['success'] = false;
}

to:

if ( ! $cmd) {
    printf("Error message: %s\n", $connect->error);
    die(); # stop this test execution here.

    $response['err'] = "Tekkis viga andmete küsimisel!";
    $response['success'] = false;
}

# optional, but useful to avoid wrong executions
else
{
    # execute the query
}

If you're still using ajax then use the response array, but the lack of the ELSE statement, in case of wrong input/setting, will continue to execute the script generating errors like previous.

Reference: http://www.php.net/manual/en/mysqli.error.php

cereal 1,524 Nearly a Senior Poster Featured Poster

Not tested, but if I'm not wrong this $cmd->bind_param("s", $where); will insert the value of $where as a string, so:

'autod.mark=7'

instead of:

`autod`.`mark`=7

If you try to display the error of the query you should get something like:

 Warning | 1292 | Truncated incorrect INTEGER value: 'autod.mark=7'