cereal 1,524 Nearly a Senior Poster Featured Poster

I would say there are many drawbacks with shared hostings. What do you need it for?

Personally I try to avoid them. Once I was asked to find why a specific website at a specific hour stopped working, after some research I saw that MySQL had max_user_connections & max_connections set to 161 (which is very low). In practice one of the other websites opened so many permanent connections, during that hour, that the pool of the server was saturated, so all the other attempts were going in timeout.

Similar issues happens if the open file limit of MySQL is to low and if in the server there are too many tables, which are files. If the limit is reached, then it causes accessing errors.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

your question is very vague. Can you clarify the exact issue?

cereal 1,524 Nearly a Senior Poster Featured Poster

@Kurk

Hi,

you could compare proxy servers with VPN, but this thread topic is about web servers so, if you want to explain better your issue, you should create a new thread. Regarding the second question, the answer is no, or probably: unrelated.

cereal 1,524 Nearly a Senior Poster Featured Poster

// EDIT
I just saw your reply, I'm glad you solved!

// Old answer
Hmm,

as far $permissions is defined by the input and defaulting to the database and not like an array:

$permissions = ((isset($_POST['permissions']) && $_POST['permissions'] != '')?sanitize($_POST['permissions']):$User['permissions']);

you can hardcode the options in the select tag, and then just compare which is set:

<select name="permissions">
    <option value="editor" <?php echo (0 == strcasecmp($permissions, 'editor')) ? ' selected="selected"' : ''; ?>>Editor</option>
    <option value="admin,editor" <?php echo (0 == strcasecmp($permissions, 'admin,editor')) ? ' selected="selected"' : ''; ?>>Admin,Editor</option>
</select>

For the sanitazation you could also write:

$permissions = filter_input(INPUT_POST, 'permissions', FILTER_SANITIZE_STRING) ? : $User['permissions'];

filter_input() will fail to FALSE or NULL if the filter fails or the input is not set, in both cases will fallback to $User['permission'], instead, it will return a string on success.

I usually manage selects through two functions:

if ( ! function_exists('_form_select'))
{
    /**
     * Create <select>
     *
     * $array_options format:
     *
     *  'option value' => 'text'
     * 
     * @param  string $name
     * @param  string $label
     * @param  array  $array_options
     * @param  string $selected
     * @return string
     */
    function _form_select($name, $label, $array_options, $selected = FALSE)
    {
        $template = '
        <label for="%1$s">%2$s</label>
        <select name="%1$s" id="%1$s">
            %3$s
        </select>
        ';

        $options = '';

        foreach($array_options as $key => $value)
            $options .= _form_options($key, $value, $selected);        

        return sprintf($template, $name, $label, $options);
    }
}

if ( ! function_exists('_form_options'))
{
    /**
     * Create <option>
     * 
     * @param  string  $key
     * @param  string  $value
     * @param  boolean $selected
     * @return string
     */
    function _form_options($key, …
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

you are trying to iterate the same result set two times: on line 28 and 106. On line 28 you get the first row, so if the query returns only one, you don't get anything when you call mysqli_fetch_assoc() again on line 106. You can use $User otherwise, if you need to loop again, insert data_seek() at line 105:

mysqli_data_seek($userResults, 0);

This will rewind the result set. Documentation:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

it can depend on the path of the files, for example:

$xls  = "Sealing Report/{$date}/sealing_production.xls";
$xls1 = "Sealing Report/{$date}/sealing_assembly.xls";

the path is relative to the script position, so if the files are in the same directory of the main index.php, then change them to:

$xls  = FCPATH . "Sealing Report/{$date}/sealing_production.xls";
$xls1 = FCPATH . "Sealing Report/{$date}/sealing_assembly.xls";

the FCPATH constant is set in the main index.php file and refers to the directory of this file. Also you could serve an array list to the function, so:

$attach_list = [$xls, $xlsl];

Once you have done this, add the $attachments argument to your function and a loop to add the files to the message:

<?php

function sendfullmail($receipient, $title, $message, $cc = '', $bcc = '', $attachments = [])
{
    $this->load->library('email');

    $this->email->from($this->from, $this->fromname);
    $this->email->to($receipient);

    if('' !== $cc)
        $this->email->cc($cc);

    if('' === $bcc)
        $bcc = 'sindisystem@gmail.com';

    else
        $bcc .= ',sindisystem@gmail.com';

    $this->email->bcc($bcc);

    if(is_array($attachments) && 0 < ($c = count($attachments)))
        for($i = 0; $i < $c; $i++)
            $this->email->attach($attachments[$i]);

    elseif(is_string($attachments))
        $this->email->attach($attachments);

    $this->email->subject($title);
    $this->email->message($message);
    $this->email->set_alt_message($this->alt);
    return $this->email->send();
}

$xls  = FCPATH . "Sealing Report/{$date}/sealing_production.xls";
$xls1 = FCPATH . "Sealing Report/{$date}/sealing_assembly.xls";

// or submit a string: $attach_list = $xls;
$attach_list = [$xls, $xlsl];

sendfullmail('recipient@mail.tld', 'Hello', 'here you go', '', '', $attach_list);

If by adjusting the path it still does not work, then set send() to FALSE and add the print_debugger() method:

// You need to pass FALSE while sending in order for the email data
// to not be cleared - if that happens, print_debugger() would have
// nothing to …
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

if your target is worldwide, then provide an English version of the site: not only of the contents, but also of the links. See this for example:

http://iraniantranslate.com/%D8%AF%D8%B1%D8%A8%D8%A7%D8%B1%D9%87-%D9%85%D8%A7/

which on the browser bar displays http://iraniantranslate.com/درباره-ما/, but if I use the browser option Copy link address then I get the encoded version which doesn't help to understand the meaning of the link. Also not all pages look complete.

pty commented: Sound advice +9
cereal 1,524 Nearly a Senior Poster Featured Poster

I found your Facebook in #1 position with web design jakarta. advance web studio

I also found Daniweb in 4th position with those keywords :D

What other things that I missed ?

When using Google, keep in mind the bubble

rproffitt commented: Same-dom, mega-filter, bubbles may mean folk that chase SEO, chase SEO. (snipe hunting?) +12
cereal 1,524 Nearly a Senior Poster Featured Poster

You're welcome :)

As I said the script block must be placed at the bottom of the <body> block, after all the other codes, so:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
  <style type="text/css">
    body {
      font-family:Arial, sans-serif;
    }

    #wrapper {
      margin-left:300px;
    }

    .column {
      float: left;
    }

    .column div {
      border: 1px solid #000;
      padding: 4px;
      margin: 2px;
      width: 15px;
      height: 15px;
      text-align: center;
      cursor: pointer;
    }

  </style>
</head>
<body>

  <div id="wrapper">
   <div id="Content">

      <p>
        <input class="btn_colors" data-color="#007FFF" type="button" name="blue" id="blue" value="Blue" />
        <input class="btn_colors" data-color="#F2B400" type="button" name="yellow" id="yellow" value="Yellow" />
        <input class="btn_colors" data-color="#66B447" type="button" name="green" id="green" value="Green" />
      </p>

      <div class="column">
        <div>20</div>
        <div>60</div>
      </div>
      <div class="column">
        <div>72</div>
        <div>71</div>
      </div>
      <div class="column">
        <div>88</div>
        <div>87</div>
      </div>
      <div class="column">
        <div>64</div>
        <div>53</div>
      </div>
      <div class="column">
        <div>90</div>
        <div>79</div>
      </div>
      <div class="column">
        <div>54</div>
        <div>73</div>
      </div>
      <div class="column">
        <div>74</div>
        <div>63</div>
      </div>
      <div class="column">
        <div>98</div>
        <div>57</div>
      </div>
      <div class="column">
        <div>74</div>
        <div>63</div>
      </div>

    </div>
  </div>

  <script type='text/javascript'>

    // variables
    var buttons = document.getElementsByClassName('btn_colors');
    var numbers = document.querySelectorAll('.column > div');
    var current_color = document.getElementById('green').getAttribute('data-color');

    // listener for button clicks
    for (let i = 0, c = buttons.length; i < c; i++)
      buttons[i].addEventListener('click', set_color, {
        passive: false
      });

    // listener for number cells
    for (let i = 0, c = numbers.length; i < c; i++)
      numbers[i].addEventListener('click', set_bg, {
        passive: false
      });

    // functions
    function set_color(event) {
      event.preventDefault();
      current_color = this.getAttribute('data-color');
    }

    function set_bg(event) {
      if(this.classList.contains('clicked'))
      {
        this.classList.remove('clicked');
        this.style.backgroundColor = 'transparent';
        return ;
      }

      this.style.backgroundColor = current_color;
      this.classList.add('clicked');
    }

  </script>

</body>
</html>

In this position the browser has already parsed …

diafol commented: Beautiful +15
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

you can use plain javascript:

// variables
var buttons = document.getElementsByClassName('btn_colors');
var numbers = document.querySelectorAll('.column > div');
var current_color = document.getElementById('green').getAttribute('data-color');

// listener for button clicks
for (let i = 0, c = buttons.length; i < c; i++)
  buttons[i].addEventListener('click', set_color, {
    passive: false
  });

// listener for number cells
for (let i = 0, c = numbers.length; i < c; i++)
  numbers[i].addEventListener('click', set_bg, {
    passive: false
  });

// functions
function set_color(event) {
  event.preventDefault();
  current_color = this.getAttribute('data-color');
}

function set_bg(event) {
  if(this.classList.contains('clicked'))
  {
    this.classList.remove('clicked');
    this.style.backgroundColor = 'transparent';
    return ;
  }

  this.style.backgroundColor = current_color;
  this.classList.add('clicked');
}

And in the HTML part just add data-color="COLOR" and class="btn_colors" to the buttons, where COLOR is the name or the code to assign to the backgroundColor property:

<p>
    <input class="btn_colors" data-color="#007FFF" type="button" name="blue" id="blue" value="Blue" />
    <input class="btn_colors" data-color="#F2B400" type="button" name="yellow" id="yellow" value="Yellow" />
    <input class="btn_colors" data-color="#66B447" type="button" name="green" id="green" value="Green" />
</p>

Live example: https://jsfiddle.net/tsLgtzkv/

In your case, in your example you were not loading JQuery, and not setting to run on onDomready. In my example there is no dependency, but it should run in the body, after all the HTML, to allow the browser to complete the parsing.

Mati_1 commented: Excellent! +0
cereal 1,524 Nearly a Senior Poster Featured Poster

@Queen_2

Hi,

have you solved?

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

I see this happens on Linux Chromium too, here's a demo: https://jsfiddle.net/tzd1gyjf/
Looking at the bug list it seems to be an intended behaviour:

But it still does not explain how the FB notification looks so different.

cereal 1,524 Nearly a Senior Poster Featured Poster

But the tag? :o

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

if you expect only one single row from the query, then instead of:

$result = $this -> global_model -> query($query) -> result();

Use row():

$result = $this -> global_model -> query($query) -> row();

So you can do:

echo $result->idmsul;

Otherwise use a loop. See the documentation at:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

if you don't want to allow duplicates then set a unique constraint to the brand column, and then use INSERT IGNORE ..., INSERT ... ON DUPLICATE KEY UPDATE ... or a regular update query. An example:

create table `brands` (
  `id` int unsigned auto_increment primary key,
  `brand` varchar(100) unique not null
) engine = innodb;

insert into `brands` (`brand`) values('sony'),('canon'),('nikon'),('fuji'),('pentax'),('zeiss');

> select * from `brands` order by `id`;
+------+---------+
|   id | brand   |
|------+---------|
|    1 | sony    |
|    2 | canon   |
|    3 | nikon   |
|    4 | fuji    |
|    5 | pentax  |
|    6 | zeiss   |
+------+---------+
6 rows in set
Time: 0.003s

Now, if you try a regular insert, you get an error for duplicated entry:

> insert into `brands` (`brand`) values('Canon');
(1062, "Duplicate entry 'Canon' for key 'brand'")

If instead you use the INSERT ... ON DUPLICATE KEY UPDATE ... the existing row gets updated and your script can continue:

> insert into `brands` (`brand`) values('Canon') on duplicate key update `brand` = 'Canon';
> select * from `brands` order by `id`;

+------+---------+
|   id | brand   |
|------+---------|
|    1 | sony    |
|    2 | Canon   |
|    3 | nikon   |
|    4 | fuji    |
|    5 | pentax  |
|    6 | zeiss   |
+------+---------+
6 rows in set
Time: 0.003s

What can happen? If in the edit form you select Canon id, and in the input field you write Zeiss, with this …

diafol commented: Great +15
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

the AJAX request seems fine and the server side too. It could be a mistype, I see in the form you set tittle with two Ts, are you sure it's the same in the database table?

$article->tittle = $tittle;

If that's okay, see if Laravel error log helps.

cereal 1,524 Nearly a Senior Poster Featured Poster

Seen that message many times, never seen a solution.

Seen that message many times, never seen a solution.

JamesCherrill commented: Seen that message many times, never seen a solutioSeen that message many times, never seen a solution. +0
cereal 1,524 Nearly a Senior Poster Featured Poster

It should be easy, in practice there are 5 select queries that group the rows by the choosen pairs, in the case below the pair is composed by the columns b1 and b2:

SELECT b1 AS 'x', b2 AS 'y', tot
  FROM (SELECT b1, b2, COUNT(id) AS tot
          FROM numbers
         GROUP BY b1, b2
         ORDER BY tot DESC)
    AS sub
 WHERE sub.tot > @threshold

each following query moves to the next column, so you go from b1,b2 to b2,b3 and so on until you reach the last b5,b6.

The UNION ALL statement is used to return the results together. Otherwise you should run five separated requests. It's not a join because each result is separated from the others, the database engine checks only that, the number of columns defined in the SELECT statements, matches all along the query. By using strings it would look like this:

> select 'a', 'b' union all select 'b', 'c' union all select 'c', 'd';

+-----+-----+
| a   | b   |
|-----+-----|
| a   | b   |
| b   | c   |
| c   | d   |
+-----+-----+

With such approach if 20,21 is repeated 3 times in b1,b2 and one time in b2,b3 you will get only 3, not 4. I don't know what you expect, but in case you want 4 then RJ's approach is probably the best, or at least you could use these queries as base for a script.

Right now it does not enter on my mind how to fix …

cereal 1,524 Nearly a Senior Poster Featured Poster

As example:

-- table definition
CREATE TABLE `numbers` (
  `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
  `b1` tinyint(3) unsigned DEFAULT NULL,
  `b2` tinyint(3) unsigned DEFAULT NULL,
  `b3` tinyint(3) unsigned DEFAULT NULL,
  `b4` tinyint(3) unsigned DEFAULT NULL,
  `b5` tinyint(3) unsigned DEFAULT NULL,
  `b6` tinyint(3) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- sample data
INSERT INTO `numbers`
VALUES (1, 6, 8, 10, 26, 27, 36),
       (2, 2, 5, 10, 11, 32, 42),
       (3, 20, 21, 23, 24, 29, 38),
       (4, 3, 4, 17, 19, 33, 49),
       (5, 2, 17, 20, 23, 33, 41),
       (6, 1, 12, 13, 20, 31, 48),
       (7, 20, 21, 26, 41, 44, 47),
       (8, 3, 4, 43, 44, 46, 47),
       (9, 6, 7, 20, 23, 29, 46),
       (10, 1, 5, 13, 20, 46, 40),
       (11, 2, 5, 10, 18, 47, 40),
       (12, 20, 21, 23, 23, 37, 39),
       (13, 3, 4, 17, 25, 38, 41),
       (14, 5, 17, 20, 29, 30, 41),
       (15, 12, 14, 28, 31, 32, 43);

-- query
> SELECT * FROM numbers;
+------+------+------+------+------+------+------+
|   id |   b1 |   b2 |   b3 |   b4 |   b5 |   b6 |
|------+------+------+------+------+------+------|
|    1 |    6 |    8 |   10 |   26 |   27 |   36 |
|    2 |    2 |    5 |   10 |   11 |   32 |   42 |
|    3 |   20 |   21 |   23 |   24 |   29 |   38 |
|    4 |    3 |    4 |   17 |   19 |   33 |   49 |
|    5 …
cereal 1,524 Nearly a Senior Poster Featured Poster

@Gi

What do you mean by multiple texts line per line? Can you share an example? Also, it would be a lot better if you start your own new thread.

cereal 1,524 Nearly a Senior Poster Featured Poster

As far as I know, years ago it was allowed and then removed. So that's great, now I can annoy people with bold statements! :D

Jay_33 commented: That's it. u're totally right +0
cereal 1,524 Nearly a Senior Poster Featured Poster

but there's no PM option.

I remember that without reputation points a new user cannot send private messages. It probably depends on this. Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

You can also try by email https://www.daniweb.com/welcome/contact just keep in mind timezones.

cereal 1,524 Nearly a Senior Poster Featured Poster

Just a note: if you are trying to use InstagramCrawler then the errors says it does not find the geckodriver which is included in one of the two required packages installed throught the pip command at the bottom of the GitHub page:

pip install -r requirements.txt

Which in practice are:

Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

I remember it was used to reduce overheating issues. I cannot find the article anymore but search for Dynamic Thermal Management techniques.

rproffitt commented: That's hot. +12
rubberman commented: Definitely hot! Impact upon performance is minimal, but impact (positive) on thermal issues is major. +14
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

that's a JSONP response, so in order to process this through PHP you need to remove the callback function that wraps the JSON data, for example:

callback({JSON DATA});

At this point you can remove it from the string:

<?php

$jsonp = 'callback({"name": "micheal"});';
$callb = 'callback'; // to remove

$s = substr($jsonp, mb_strlen($callb) + 1); // +1 to include the opening `(`
$s = substr($s, 0, -2); // -2 to remove `);`

print_r(json_decode($s, true));

Now, most JSON servers allows the client to define a callback in the requesting link:

http://url/page.php?callback=foo

So you receive:

foo({JSON DATA});

This allows you to write a more robust solution, as it's should not affect your script if they change their default callback function. See also if the server allows to get other formats, like simple JSON or XML.

cereal 1,524 Nearly a Senior Poster Featured Poster

Embedded contens like YouTube and Vimeo are served by them directly to the client, your page just sends the resource link, then the client opens a connection to the resource. You can see this through the developer console in Chrome: select the Network tab, hit reload for your page and see how the browser start to request data do different domains.

This means that your website bandwidth is not affected by these streams. It would if the video file was hosted and streamed by your server. Or if it was streamed as a proxy system from your web server to the clients connecting to your domain, an example:

It's the same with Google fonts or javascript libraries served by CDN systems.

rproffitt commented: Good explanation of how things work. +12
cereal 1,524 Nearly a Senior Poster Featured Poster

I honestly do not know. I don't doubt what you say, but I don't see how the original script could work with a base64 string, regardless if it was hosted locally or remote. Maybe the input was sent via the pixel $_POST['type']? In that case $im could be populated correctly.

cereal 1,524 Nearly a Senior Poster Featured Poster

This brings me straight to 2000-2003 years, at that time I was working in a small lab assembling & repairing computers, the worst was when people wanted to recover EFS encrypted files from Windows XP drives. Windows XP policy was insane, they allowed to use EFS without a recovery agent, so people could backup the files, format the disk, reinstall Windows and ta-da when copying back they could not anymore access the files. You try to explain that using the same username would not lead to success and that an additional step, previous to the encryption, was needed but nothing. The only available solution that I knew was to try to recover the temporary copy created when processing the file, but at that time it was really difficult to find information and open source solutions, at least to try.

Lately, instead, I was able to recover data from a damaged CF card through PhotoRec: http://www.cgsecurity.org/wiki/PhotoRec
actually it recovered not only the shoot day but also jobs from the last year.

cereal 1,524 Nearly a Senior Poster Featured Poster

However internalImageUpload() writes only to the database.

Instead, it's in:

imagejpeg($im, $upload_path.$filename);

I overlooked that, and yes by defining a second parameter you would save the resource loaded into $im. However you cannot inject (as far as I know) the contents from $_POST['image'] to $im.

Try something like this:

<?php

$uid      = $_POST['uid'];
$token    = $_POST['token'];
$group_id = $_POST['group_id'];
$needle   = $_POST['image'];
$haystack = 'data:image/png;base64,';
$png_blob = substr($needle, mb_stripos($needle, $haystack) + mb_strlen($haystack));

$upload_path = '../' . UPLOAD_PATH;
$filename    = time() . $uid . '.jpg';

// save to image folder
file_put_contents($upload_path . $filename, base64_decode($png_blob));

// save to database
internalImageUpload($uid, $filename, $group_id, FALSE);

$imageID       = internalGetUploadImage($uid, $filename);
$fullImagePath = BASE_URL . UPLOAD_PATH . $filename;

echo "<img src='".$fullImagePath."'  class='webcam_preview' id='".$imageID[0]->id."'/>";

Just make sure the path is correct, that ../ in $upload_path makes me nervous :D as it would always be relative to the link in the frontend side and to the system path in the backend side.

cereal 1,524 Nearly a Senior Poster Featured Poster

So, how would you write the image to the image folder? Through internalImageUpload()?

cereal 1,524 Nearly a Senior Poster Featured Poster

The point is that you cannot use $_POST['image'] that way. See the definition of imagecreatefrompng():

resource imagecreatefrompng ( string $filename )

It means it expects a string to define the filename, not the contents. Something that would work would be:

$im = imagecreatefrompng('file.png');

And from here you create a resource that will be saved into file.png, you cannot import the value of $_POST['image'] into this resource. The value in $_POST['image'] is a base64 encoded string, which once decoded is a binary blob.

Hence, you don't need that code to save the input.

For more details, take this part:

$image = $_POST['image'];
$filter_image = str_replace("data:image/png;base64,", "", $image);
// input is in format 1,2,3...|1,2,3...|...
if($filter_image == $invalid)
{
    $im = "";
    echo "false";
}
else
{
    $im = imagecreatetruecolor(320, 240);
    foreach (explode("|", $_POST['image']) as $y => $csv) {
        foreach (explode(";", $csv) as $x => $color) {
            imagesetpixel($im, $x, $y, $color);
        }
    }
}

the comment says the expected format is: 1,2,3...|1,2,3...|... but it is not like this, it is something like:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKAQMAAAC3/F3+AAAABGdBTUEAAYagMeiWXwAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABlBMVEUA///+/v7eZjVAAAAAAWJLR0QB/wIt3gAAAAd0SU1FB+EIAQ0VMIC0C8gAAAALSURBVAjXY2DABwAAHgABboVHMgAAAABJRU5ErkJggg==

Which, decoded with my post.php script, produces a 10x10 cyan PNG image. Call it a.png.

The IF statement: if($filter_image == $invalid) is trying to compare an hardcoded blank blob to what is received by $_POST, to make sure it's not an empty snapshot. This can easily fail because the PNG specification allows to set a tIME value everytime the file is modified (or created), in practice some softwares as Gimp and in some cases ImageMagick, will add it …

cereal 1,524 Nearly a Senior Poster Featured Poster

@Jim_16

Hi, please read again: the OP wants read-only access for everyone.

cereal 1,524 Nearly a Senior Poster Featured Poster

Okay, I got it to work, the JS function will export the canvas contents to PNG:

snapshot.toDataURL('image/png')

so, what you get in$_POST['image'] is a base64 encoded blob. All you need to do is to remove the data:image/png;base64, part, as you were doing, decode the remaining string and save it to a file, at basic:

$needle      = $_POST['image'];
$haystack    = 'data:image/png;base64,';
$png_blob    = substr($needle, mb_stripos($needle, $haystack) + mb_strlen($haystack));
$destination = __DIR__ . '/image.png';

file_put_contents($destination, base64_decode($png_blob));

So if $needle is data:image/png;base64,AAA..., $png_blob will be AAA. You don't need the GD functions unless you want to test if the resulting file is really a PNG and not a script.

Full test:

<!DOCTYPE html>
<html>
<head>
    <title>Capture</title>
</head>
<body>

    <video id="player" width="480px" height="240px" autoplay="true"></video>
    <button id="takeSnap" class="startbutton messageButton">Take Snap</button>

    <div id="webcam">
        <input type="hidden" id="uploadvalues">
        <canvas id="snapshot"></canvas>
        <div id="webcam_preview"></div>
    </div>

    <h3>Reload to see latest snapshot</h3>
    <img src="image.png">

    <script type="text/javascript" src="https://unpkg.com/jquery@3.2.1"></script>
    <script type="text/javascript">

        var captureButton = document.getElementById('takeSnap');
        var snapshot      = document.getElementById('snapshot');
        var video         = document.getElementById('player');

        // @see https://www.kirupa.com/html5/accessing_your_webcam_in_html5.htm

        navigator.getUserMedia  = navigator.getUserMedia
                               || navigator.webkitGetUserMedia
                               || navigator.mozGetUserMedia
                               || navigator.msGetUserMedia
                               || navigator.oGetUserMedia;

        if (navigator.getUserMedia)       
            navigator.getUserMedia({video: true}, handleVideo, videoError);

        function handleVideo(stream) {
            video.src = window.URL.createObjectURL(stream);
        }

        function videoError(e) {
            // do something
        }

        captureButton.addEventListener('click', function(e)
        {
            var context = snapshot.getContext('2d');

            // Draw the video frame to the canvas.
            context.drawImage(player, 0, 0, snapshot.width, snapshot.height);

            //start webcam upload
            var webcamURL = 'post.php';

            $.post(webcamURL, {type: 'data', image: snapshot.toDataURL('image/png')}, function(data) {
                    if(data)
                    {
                        var values = $('#uploadvalues').val();

                        $('#webcam_preview').prepend(data);

                        var X = $('.webcam_preview').attr('id');

                        if ($.trim(values).length > 0)
                            var Z = X + ',' + values; …
diafol commented: Going the extra mile, again :) +1 +15
rproffitt commented: Nice work. +12
cereal 1,524 Nearly a Senior Poster Featured Poster

Hmm, what kind of input do you expect in $_POST['image']?

Because imagecreatefromjpeg() expects a string to be used like a file name. You are submitting $_POST['image'] instead, which it appears to be a base64 encoded string, and from the previous PHP code, it seems it should be a list of PNG image blobs.

At line 20 you have:

$filter_image = str_replace("data:image/png;base64,", "", $image);

But in the loop you refer again to $_POST['image'] so when you explode by the pipe and semi-colon chars, in practice you end up with:

$x[] = 'data:image/png';
$x[] = 'base64,HEX_STRING';

i.e. two strings that cannot be decoded by base64_decode() which, by the side, is not used in your code.

The imagesetpixel() function, instead expects an integer for the $color argument... and here I get lost because I don't understand anymore what should be the contents of $_POST['image'].

cereal 1,524 Nearly a Senior Poster Featured Poster

Could it be my RAM is problem?

Hmm, have you tried powering without RAM modules? If everything is fine up to memory check (psu & cpu) then if you power without ram it should fail with a beep code for memory failure. Does CPU fan spin?

cereal 1,524 Nearly a Senior Poster Featured Poster

@Mohd_9

Hi,

it could be the power supply or a RAM module. Do you hear any beeps when turning on? And if yes, how many? Each BIOS has is own codes and can give an idea of what is wrong, for example Intel's:

Also, are the fans spinning? If you can, test with another power supply. When testing unplug all disks from motherboard and see if you can get to the BIOS. If the power supply is fine then you would remove all peripherals and test each RAM module separately by moving the RAM into each (RAM) slot, to understand: if all RAM modules and slots are fine. And then move to each peripheral, until you isolate the problem.

NOTE - please, always be sure to have unplugged the computer from power electricity BEFORE you put your hands into the tower.

cereal 1,524 Nearly a Senior Poster Featured Poster

@UI

Something similar and probably more sane exists, see https://bountify.co/

There you can see each solution, unless the parts decide to use private messages. It works like this:

  • the requester sets a bounty, the range goes from 1 to 100 USD (before it allowed up to 500 USD) and it will stay active for 7 days
  • the requester pays the bounty upfront, on this stage he also pays a small fee to the website
  • if users decide to reply they usually use gist.github.com or pastebin & co. to share their solutions
  • the requester can discuss with each participant to fix the solutions
  • if the requester is happy with one of the provided solutions he/she can assign the bounty to the author
  • at this point the winner can receive the bounty

An example: https://bountify.co/help-converting-a-flat-json-file-into-hierarchical-json-schema-to-use-with-d3-treemap

If the requester does not choose a winner, or the winner does not withdraw the prize, after seven days the bounty will go to charity. Right now there is only one available, last time I checked there where a couple more, I think there was EFF also.

They have been up for the last five years and receive 3-4 requests per week.

Most of the time bounties are very low but people answer because they want to compete or try to solve the requests. However, I think this does not fit Daniweb and in general, forums.

If you think your idea can work, then put it up and see what you get.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

which Windows version are you using? Version 7 and previous, for example, miss this procedure.

cereal 1,524 Nearly a Senior Poster Featured Poster

Can you change excel sheet and make it importable into mysql tables?

Yes, it can be done. You can convert it to CSV and the use fgetcsv() and prepared statements. Search for PHPExcel or similar. If you use MariaDB, a MySQL fork, then you can use the ODBC connect engine to attach the excel file to a table and run a query to insert the rows into the destination table, see:

cereal 1,524 Nearly a Senior Poster Featured Poster

It can, in order to work the service should return status code 307 or 308, as example:

<?php

header('HTTP/1.1 307 TEMPORARY REDIRECT');
header('Location: http://destination.tld/post.php');
exit;
cereal 1,524 Nearly a Senior Poster Featured Poster

Harri seems to be a spammer (human?), a quick search revealed many posts with the same text:

cereal 1,524 Nearly a Senior Poster Featured Poster

Keep in mind also that a lack of vitamin B favors insomnia. As thyroid issues like hyperthyroidism.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hehe, it will be fun, don't worry ;D

gentlemedia commented: Not sure about the fun part. Necessary? Yes! Bur fun...? :) +7
cereal 1,524 Nearly a Senior Poster Featured Poster

I got a message back from the provider and it's indeed not possible to edit the php,ini file because it's not only used by mine hosting package also by others. That kind of sucks!

Indeed, it sucks :| Not considering that they could use pools to provide separated resources and configuration files for each client.

I will ask if I can create a custom php.ini file in my own dcucment root to override settings.

Either that or my first suggestion: through prepended scripts, which should work for directives that can be applied at runtime, see:

cereal 1,524 Nearly a Senior Poster Featured Poster

Do you mean with a dedicated interface a thing like cPanel?

Yes. Sometimes you can edit configuration files only through these forms. You can, also, try to write a custom php.ini file and save it into the document root, success however depends on hosting configuration: if it is allowed then it will override the defaults.

cereal 1,524 Nearly a Senior Poster Featured Poster

Try sudo -u admin instead >:]

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi!

Are you using PHP-FPM? In such cases the PHP engine can be located into another server and accessed through an IP address. The address is configured in the web server config files and the php.ini file is in the remote server. You can probably use ini_set() by including a script in top of the others. Through .htaccess this is done like this:

php_value auto_prepend_file "/path/to/iniset.php"

Otherwise in PHP:

require "/path/to/iniset.php";

I would also check with hosting documentation to see if you can set the directives through a dedicated interface.

cereal 1,524 Nearly a Senior Poster Featured Poster

Comment the rules in the .htaccess file and try again to access /admin. If you get redirected post the code of /admin.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi davy,

the .htaccess seems to be fine, so I have some questions for you:

  • which web server are you using?
  • Are you using a virtual host config?
  • Which is the document root?
  • What do you expect to get instead of http://localhost/dashboard ?