PHP - Escrbir un archivo con PHP

 
Vista:

Escrbir un archivo con PHP

Publicado por Davud (1 intervención) el 29/05/2015 12:05:54
Hola,

He creado un PHP que comprueba el color de un pixel en una imagen.
Este PHP escribe en un archivo los valores y más adelante los lee.
Hasta aquí todo bien.
La pruebo con el navegador y funciona correctamente, pero si lo ejecuto por la shell de mi proveedor no funciona.
He buscado mucho por internet pero no encuentro la solucion.

Pego aqui el codigo.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
require "twitteroauth-master/autoload.php";
include_once 'Abraham\\TwitterOAuth\\TwitterOAuth';
 
//Hora europa
putenv('TZ=Europe/Madrid');
$hora_europa = date("H");
 
$nom_mes= array('de gener','de febrer','de març','d\'abril','de maig','de juny','de juliol','d\'agost','de setembre','de octubre','de novembre','de desembre');
 
$data_avui = date_create($data);
//echo 'Avui->'.date_format($data_avui, 'd-m-Y');
$dia_avui=date_format($data_avui,'d');
$mes_avui=date_format($data_avui,'m');
$any_avui=date_format($data_avui,'Y');
 
//echo '<br>';
$data_dema = date_create($data);
date_add($data_dema, date_interval_create_from_date_string('1 day'));
//echo 'Dema->'.date_format($data_dema, 'd-m-Y');
$dia_dema=date_format($data_dema,'d');
$mes_dema=date_format($data_dema,'m');
$any_dema=date_format($data_dema,'Y');
 
//echo '<br>';
//echo"Aqui els avisos. <br>";
 
$im_avui = imagecreatefrompng("http://static-m.meteo.cat/content/smp/mapa/".$dia_avui."-".$mes_avui."-".$any_avui."_global.png");
$im_dema = imagecreatefrompng("http://static-m.meteo.cat/content/smp/mapa/".$dia_dema."-".$mes_dema."-".$any_dema."_global.png");
//Noms de cada poble (lugar1,lugar2,lugar3,lugar4,)
$poble=array(lugar1,lugar2,lugar3,lugar4,);
//Coordenades x de cada poble (lugar1,lugar2,lugar3,lugar4,)
$x=array(1,1,2,3);
//Coordenades y de cada poble (lugar1,lugar2,lugar3,lugar4,)
$y=array(1,1,2,3);
//Array de cada color segons poble
$avisos=array("","","","","","","","");
 
//Si son les 9 del mati esborro el contingut de l'arxiu
if($hora_europa==9){
	//Desar al arxiu els colors
	$fp = fopen('avisos.txt', 'w');
	for($j=0;$j<=7;$j++){
		fwrite($fp, "");
		fwrite($fp, "\n");
	}
	fclose($fp);
}
else{
	//Obre l'arxiu per veure si hi ha un avis
	$color= file('http://molner.es/php/avisos.txt');
	for($j=0;$j<=7;$j++){
		$trimmed = trim($color[$j], " \n.");
		$color[$j]=$trimmed;
	}
}
 
 
 
//Obre l'arxiu per veure si hi ha un avis
//$color= file('http://molner.es/php/avisos.txt');
//for($j=0;$j<=7;$j++){
//	$trimmed = trim($color[$j], " \n.");
//	$color[$j]=$trimmed;
//}
//var_dump($color);
//echo'<br>';
//echo'Avui->'.$dia_avui."-".$mes_avui."-".$any_avui;
echo'<br>';
$j=0;
for($k=0;$k<=1;$k++){
	if($k==0){
		$dia="avui";
		$imatge=$im_avui;
	}
	else{
		$dia="dema";
		$imatge=$im_dema;
	}
	for ($i=0;$i<=3;$i++){
		$rgb = imagecolorat($imatge, $x[$i], $y[$i]);
//		echo "<br>".$rgb."=>".$poble[$i]."==>";
		if($rgb==11847720){
			$color[$j]='verd';
		}
		elseif($rgb==16765696){
			if($color[$j]=='groc'){
				if($hora_europa==15||$hora_europa==21){
					$inici_frase="Recordeu que hi";
					dades_twitt($poble[$i],$color[$j],$dia,$inici_frase);
				}
			}
			else{
				$color[$j]='groc';
				$inici_frase="Hi";
				dades_twitt($poble[$i],$color[$j],$dia,$inici_frase);
			}
		}
		elseif($rgb==15309589){
			if($color[$j]=='taronja'){
				if($hora_europa==15||$hora_europa==21){
					$inici_frase="Recordeu que hi";
					dades_twitt($poble[$i],$color[$j],$dia,$inici_frase);
				}
			}
			else{
				$color[$j]='taronja';
				$inici_frase="Hi";
				dades_twitt($poble[$i],$color[$j],$dia,$inici_frase);
			}
		}
		elseif($rgb==13568288){
			if($color[$j]=='vermell'){
				if($hora_europa==15||$hora_europa==21){
					$inici_frase="Recordeu que hi";
					dades_twitt($poble[$i],$color[$j],$dia,$inici_frase);
				}
			}
			else{
				$color[$j]='vermell';
				$inici_frase="Hi";
				dades_twitt($poble[$i],$color[$j],$dia,$inici_frase);
			}
		}
//		echo '<br>';
		$j=$j+1;
	}
}
 
 
//var_dump($color);
//Desar al arxiu els colors
$fp = fopen('avisos.txt', 'w');
for($j=0;$j<=7;$j++){
	fwrite($fp, $color[$j]);
	fwrite($fp, "\n");
}
///////////
//Arxiu control
fclose($fp);
$fp = fopen('hora.txt', 'w');
fwrite($fp, $hora_europa);
fwrite($fp, "\n");
fclose($fp);
//////////
 
?>
Aquí esta el codigo para enviar los twitts.
Gracias,
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder