Entries Tagged as 'language'

Only variables should be passed by reference – php end()

See : http://bugs.php.net/bug.php?id=48937

If you’re using something like this:

$itemsArray[]= end(explode('/',$item));

change to this:
$parts = explode('/',$item);
$itemsArray[]= end($parts);
This is a PHP "type juggling" issue
http://php.net/manual/de/language.types.type-juggling.php

solution ex:

$nomeArq = explode(".", $arquivo["name"]);
$extArq[]= end($nomeArq);

$sql = "INSERT INTO public.arquivo
(
arqnome,
arqextensao,
arqdescricao,
arqtipo,
arqtamanho,
arqdata,
arqhora,
usucpf,
sisid
)VALUES(
'".current(explode(".", $arquivo["name"]))."',
'".$extArq[0]."',
'".$dados["arqdescricao"]."',
'".$arquivo["type"]."',
'".$arquivo["size"]."',
'".date('d/m/Y')."',
'".date('H:i:s')."',
'".$_SESSION["usucpf"]."',
". $_SESSION["sisid"] ."
) RETURNING arqid;";
$arqid = $db->pegaUm($sql)

Create, send form by javascript

sendfrm () {
formulario = document.createElement(“form”);
formulario.id = “sendform”;
formulario.action = “send.php”;
formulario.method = “POST”;
formulario.id = “sendform”;
formulario.target=’csv’;
var newField1 = document.createElement(‘input’);
newField1.setAttribute(‘name’, ‘data’);
newField1.setAttribute(‘type’, ‘hidden’);
formulario.appendChild(newField1);
formulario.elements[0].value = window.document.getElementById(‘dvRelatorio’).innerHTML;
document.body.appendChild(formulario);
var myWin = window.open(formulario.action, formulario.target,’height=100,width=200′);
formulario.submit();
}
…onclick=”sendfrm();”…

How to uncompress zip, rar, tar.gz, tar.bz2 using shell – Linux

To uncompress these files formats, type the following commands:

zip:

gunzip filename

rar:

rar x filename

tar:

gzip filename

tar.gz:

tar -vzxf filename

Php | Fatal error: Maximum execution time of x seconds exceeded

Fatal error: Maximum execution time of 30 seconds exceeded

It’s  max_execution_time    30    30 (phpinfo)

You need to change in php.ini max_execution_time value.

sudo vi  /etc/php5/apache2/php.ini

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 300     ; Maximum execution time of each script, in seconds

sudo /etc/init.d/apache2 restart

php5 + apache 2 on Ubuntu 8.04

sudo apt-get install apache2

sudo apt-get install php5

sudo apt-get install libapache2-mod-php5

sudo /etc/init.d/apache2 restart

if apache is already installed you can omit the first line. Your web files will now be found in /var/www/

Printing update using select or update from select

Tested in postgres:

Printing sql update script:

select ‘update dados.tb_geo_municipios set cras_qtde=’||cras_qtde||’ where codigo=’||codigo||’;’
from dados.tb_prog_mi_mes_mu
where mes_ano = ’2007-10-01′

select SUBSTR(codigo,1,2),sum(cras_qtde) from dados.tb_prog_mi_mes_mu
where cras_qtde>0 group by SUBSTR(codigo,1,2)

select ‘update dados.tb_geo_estado set cras_qtde=’||sum(cras_qtde)||’
where codigo=’||substr(codigo,1,2)||’;’
from dados.tb_prog_mi_mes_mu where cras_qtde>0
group by substr(codigo,1,2);

Updating from select:

update dados.tb_prog_mi_ano_estado
set pop=a.popu
from (
select substring(codigo,1,2) as cod,sum(pop) as popu from dados.tb_prog_mi_ano_mu where mes_ano=’2007-01-01′
group by substring(codigo,1,2)) a
where codigo=a.cod and mes_ano=’2007-01-01′

Sum two arrays by index using php

You can use array_map and array_sum functions:

$sum = array_map(‘array_sum’, array_map(null, $array1, $array2));

ex:

<?
$a = array(1, 2, 3, 4, 5);
$b=array(5,4,3,2,1);

$sum = array_map(‘array_sum’, array_map(null, $a, $b));

print_r ($sum);
?>

Output:

Array ( [0] => 6 [1] => 6 [2] => 6 [3] => 6 [4] => 6 )

PHP file counter (no database)

This script show you how to create a simple website counter using a file.

Create a file (counter.txt), containing the initial number 0 and save it as counter.txt.
Upload it to your server
CHMOD it to 777.

It will look like this:
0

The code:
//Print the current count
$File = “counter.txt”;
$counter = fopen($File, ‘r+’) ;
$data = fread($counter, 512) ;
$count = $data + 1;
print $count;
//Update the Text File With The New Count
fseek($counter, 0) ;
fwrite($counter, $count) ;
fclose($counter) ;