exec()
Ik zit met het volgende:
Ik wil via exec() Irfanview starten, om als eerst te testen of exec() werkt ben ik begonnen met:
Code (php)
Dit geeft het volgende resultaat:
Wat dus niet goed is. Iemand enig idee wat er verkeerd is?
Misschien nog meer info:
Ik run het bestand test.php op mijn pc, test.php staat echter op een andere server.
Info server:
windows 2003
IIS 6.0
PHP: 5.2.9-1
In php.ini:
safemode: on
safe_mode_exec_dir: C:\php\safedir
Gewijzigd op 01/01/1970 01:00:00 door Kitty N
Waarom zou dat verkeerd zijn? Heb je al gekeken of er iets in dat array() zit.
Ja heb ik al gekeken, maar daar zit niks in.
Code (php)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
<?php
$action = "ping"; //Welke actie moet er uitgevoerd worden
$arg = "spiderman"; //argumenten
//Voerde exec uit, escape de shell argument en zet je result in de array en prop deze array in de waarde $result
exec($action.escapeshellarg($arg), $return = array(), $result);
echo print_r($result,true);//print het hele zooitje
?>
$action = "ping"; //Welke actie moet er uitgevoerd worden
$arg = "spiderman"; //argumenten
//Voerde exec uit, escape de shell argument en zet je result in de array en prop deze array in de waarde $result
exec($action.escapeshellarg($arg), $return = array(), $result);
echo print_r($result,true);//print het hele zooitje
?>
Als je het nog niet hebt pm me maar ik heb ergens wel een werkend script liggen (leuk het uit het blote bolletje)
Met de code van Dreampower krijg ik ook hetzelfde resultaat.
Heb het ook nog zo geprobeerd:
Code (php)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
<?php
$action = "cmd.exe"; //Welke actie moet er uitgevoerd worden
$arg = "ping spiderman"; //argumenten
//Voerde exec uit, escape de shell argument en zet je result in de array en prop deze array in de waarde $result
exec($action.escapeshellarg($arg), $return = array(), $result);
echo print_r($result,true);//print het hele zooitje
?>
$action = "cmd.exe"; //Welke actie moet er uitgevoerd worden
$arg = "ping spiderman"; //argumenten
//Voerde exec uit, escape de shell argument en zet je result in de array en prop deze array in de waarde $result
exec($action.escapeshellarg($arg), $return = array(), $result);
echo print_r($result,true);//print het hele zooitje
?>
Maar geeft ook 0
Gewijzigd op 01/01/1970 01:00:00 door kitty N
Maak van 'ping spiderman' eens 'ping localhost'.
Code (php)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
<?php
$action = "ping"; //Welke actie moet er uitgevoerd worden
$arg = "localhost"; //argumenten
$action = "ping.exe"; //Welke actie moet er uitgevoerd worden
$arg = "localhost"; //argumenten
$action = "cmd.exe"; //Welke actie moet er uitgevoerd worden
$arg = "ping localhost"; //argumenten
?>
$action = "ping"; //Welke actie moet er uitgevoerd worden
$arg = "localhost"; //argumenten
$action = "ping.exe"; //Welke actie moet er uitgevoerd worden
$arg = "localhost"; //argumenten
$action = "cmd.exe"; //Welke actie moet er uitgevoerd worden
$arg = "ping localhost"; //argumenten
?>
Dit zou wellicht de reden kunnen zijn dat je geen results krijgt. Probeer eens een 'ping -c 4' (om het 4x uit te voeren) in je code te verwerken en kijk dan wat de resultaten zijn.
Probeer ook system() eens
Noot: Unix only
Gewijzigd op 01/01/1970 01:00:00 door Leon Vosmeijer
Leon schreef op 03.12.2009 14:55:
Ping is een systeem commando die normaliter oneindig doorgaat, totdat de gebruiker zegt dat het programma moet stoppen.
Dit zou wellicht de reden kunnen zijn dat je geen results krijgt. Probeer eens een 'ping -c 4' (om het 4x uit te voeren) in je code te verwerken en kijk dan wat de resultaten zijn.
Probeer ook system() eens
Noot: Unix only
Dit zou wellicht de reden kunnen zijn dat je geen results krijgt. Probeer eens een 'ping -c 4' (om het 4x uit te voeren) in je code te verwerken en kijk dan wat de resultaten zijn.
Probeer ook system() eens
Noot: Unix only
Leon, lees dan even verder; het is een Windows server...
Ik weet het verder ook niet TS, wellicht overstappen naar Linux? (Heeft sowieso meer voordelen dan Windows...)
In ieder geval bedankt voor het meedenken!
Kitty, wat gebruik je dan nu om de foto's te resizen?
Code (php)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
class ResizeImage {
// This is your array of supported image formats.
// Exclude types you don't want rendered.
var $valid_ext = array( 'png', 'jpg', 'jpeg', 'gif', 'bmp', 'wbmp' );
// Whether or not that script should continue
var $halt = false;
// Image Configuration array and Source Image
var $image = array();
var $s_image;
public function render ( $source ) {
$this->s_image = $source;
list( $this->image['width'], $this->image['height'] ) = getimagesize( $source );
$this->image['extension'] = strtolower( preg_replace( '/^.*\.([^.]+)$/D', '$1', $this->s_image ) );
if ( ! ( in_array( $this->image['extension'], $this->valid_ext ) ) ) {
echo 'Invalid format!';
$this->halt = true;
}
switch ( $this->image['extension'] ) {
case 'png';
$this->image['render'] = imagecreatefrompng( $this->s_image );
imagealphablending( $this->image['render'], false );
imagesavealpha( $this->image['render'], true );
break;
case 'jpg';
$this->image['render'] = imagecreatefromjpeg( $this->s_image );
break;
case 'jpeg';
$this->image['render'] = imagecreatefromjpeg( $this->s_image );
break;
case 'gif';
$this->image['render'] = imagecreatefromgif( $this->s_image );
break;
case 'bmp';
$this->image['render'] = imagecreatefromwbmp( $this->s_image );
break;
case 'wbmp';
$this->image['render'] = imagecreatefromwbmp( $this->s_image );
break;
}
}
public function contrain ( $width, $height ) {
if ( ! ( $this->halt ) ) {
if ( $this->image['extension'] == 'gif' ) {
$this->image['composite'] = imagecreatetruecolor( $width, $height );
imagecopyresample( $this->image['composite'], $this->image['render'], 0, 0, 0, 0, $width, $height, $this->image['width'], $this->image['height'] );
$this->image['colorcount'] = imagecolorstotal( $this->image['render'] );
imagetruecolortopalette( $this->image['composite'], true, $this->image['colorcount'] );
imagepalettecopy( $this->image['composite'], $this->image['render'] );
$this->image['transparentcolor'] = imagecolortransparent( $this->image['render'] );
imagefill( $this->image['composite'], 0, 0, $this->image['transparentcolor'] );
imagecolortransparent( $this->image['composite'], $this->image['transparentcolor'] );
} else {
$this->image['composite'] = imagecreatetruecolor( $width, $height );
imagecopyresample( $this->image['composite'], $this->image['render'], 0, 0, 0, 0, $width, $height, $this->image['width'], $this->image['height'] );
}
} else {
echo 'Execution halted!';
}
}
public function proportion ( $max_width, $max_height ) {
if ( ! ( $this->halt ) ) {
if ( $this->image['extension'] == 'gif' ) {
$this->image['ratio'] = ( $this->image['width'] > $this->image['height'] ) ? $max_width / $this->image['width'] : $max_height/$this->image['height'];
if( $this->image['width'] > $max_width || $this->image['height'] > $max_height ) {
$new_width = $this->image['width'] * $this->image['ratio'];
$new_height = $this->image['height'] * $this->image['ratio'];
} else {
$new_width = $this->image['width'];
$new_height = $this->image['height'];
}
$this->image['composite'] = imagecreatetruecolor( $new_width, $new_height );
imagecopyresampled( $this->image['composite'], $this->image['render'], 0, 0, 0, 0, $new_width, $new_height, $this->image['width'], $this->image['height'] );
$this->image['colorcount'] = imagecolorstotal( $this->image['render'] );
imagetruecolortopalette( $this->image['composite'], true, $this->image['colorcount'] );
imagepalettecopy( $this->image['composite'], $this->image['render'] );
$this->image['transparentcolor'] = imagecolortransparent( $this->image['render'] );
imagefill( $this->image['composite'], 0, 0, $this->image['transparentcolor'] );
imagecolortransparent( $this->image['composite'], $this->image['transparentcolor'] );
} else {
$this->image['ratio'] = ( $this->image['width'] > $this->image['height'] ) ? $max_width / $this->image['width'] : $max_height/$this->image['height'];
if( $this->image['width'] > $max_width || $this->image['height'] > $max_height ) {
$new_width = $this->image['width'] * $this->image['ratio'];
$new_height = $this->image['height'] * $this->image['ratio'];
} else {
$new_width = $this->image['width'];
$new_height = $this->image['height'];
}
$this->image['composite'] = imagecreatetruecolor( $new_width, $new_height );
imagecopyresampled( $this->image['composite'], $this->image['render'], 0, 0, 0, 0, $new_width, $new_height, $this->image['width'], $this->image['height'] );
}
} else {
echo 'Execution halted!';
}
}
public function output ( $quality = 100 ) {
if ( ! ( is_numeric( $quality ) ) ) {
$quality = 100;
}
if ( ! ( $this->halt ) ) {
switch ( $this->image['extension'] ) {
case 'png';
header( 'Content-Type: image/png' );
imagepng( $this->image['composite'], null, null );
break;
case 'jpg';
header( 'Content-Type: image/jpeg' );
imagejpeg( $this->image['composite'], null, $quality );
break;
case 'jpeg';
header( 'Content-Type: image/jpeg' );
imagejpeg( $this->image['composite'], null, $quality );
break;
case 'gif';
header( 'Content-Type: image/gif' );
imagegif( $this->image['composite'], null, $quality );
break;
case 'bmp';
header( 'Content-Type: image/wbmp' );
imagewbmp( $this->image['composite'], null, null );
break;
case 'wbmp';
header( 'Content-Type: image/wbmp' );
imagewbmp( $this->image['composite'], null, null );
break;
}
} else {
echo 'Execution halted!';
}
}
public function saveto ( $destination, $filename, $quality = 100 ) {
if ( ! ( is_numeric( $quality ) ) ) {
$quality = 100;
}
if ( ! ( $this->halt ) ) {
switch ( $this->image['extension'] ) {
case 'png';
imagepng( $this->image['composite'], $destination . $filename . '.' . $this->image['extension'], null );
break;
case 'jpg';
imagejpeg( $this->image['composite'], $destination . $filename . '.' . $this->image['extension'], $quality );
break;
case 'jpeg';
imagejpeg( $this->image['composite'], $destination . $filename . '.' . $this->image['extension'], $quality );
break;
case 'gif';
imagegif( $this->image['composite'], $destination . $filename . '.' . $this->image['extension'], $quality );
break;
case 'bmp';
imagewbmp( $this->image['composite'], $destination . $filename . '.' . $this->image['extension'], null );
break;
case 'wbmp';
imagewbmp( $this->image['composite'], $destination . $filename . '.' . $this->image['extension'], null );
break;
}
} else {
echo 'Execution halted!';
}
}
public function clear_cache () {
imagedestroy( $this->image['composite'] );
imagedestroy( $this->image['render'] );
unset( $this->image );
unset( $this->s_image );
$this->halt = false;
}
}
?>
class ResizeImage {
// This is your array of supported image formats.
// Exclude types you don't want rendered.
var $valid_ext = array( 'png', 'jpg', 'jpeg', 'gif', 'bmp', 'wbmp' );
// Whether or not that script should continue
var $halt = false;
// Image Configuration array and Source Image
var $image = array();
var $s_image;
public function render ( $source ) {
$this->s_image = $source;
list( $this->image['width'], $this->image['height'] ) = getimagesize( $source );
$this->image['extension'] = strtolower( preg_replace( '/^.*\.([^.]+)$/D', '$1', $this->s_image ) );
if ( ! ( in_array( $this->image['extension'], $this->valid_ext ) ) ) {
echo 'Invalid format!';
$this->halt = true;
}
switch ( $this->image['extension'] ) {
case 'png';
$this->image['render'] = imagecreatefrompng( $this->s_image );
imagealphablending( $this->image['render'], false );
imagesavealpha( $this->image['render'], true );
break;
case 'jpg';
$this->image['render'] = imagecreatefromjpeg( $this->s_image );
break;
case 'jpeg';
$this->image['render'] = imagecreatefromjpeg( $this->s_image );
break;
case 'gif';
$this->image['render'] = imagecreatefromgif( $this->s_image );
break;
case 'bmp';
$this->image['render'] = imagecreatefromwbmp( $this->s_image );
break;
case 'wbmp';
$this->image['render'] = imagecreatefromwbmp( $this->s_image );
break;
}
}
public function contrain ( $width, $height ) {
if ( ! ( $this->halt ) ) {
if ( $this->image['extension'] == 'gif' ) {
$this->image['composite'] = imagecreatetruecolor( $width, $height );
imagecopyresample( $this->image['composite'], $this->image['render'], 0, 0, 0, 0, $width, $height, $this->image['width'], $this->image['height'] );
$this->image['colorcount'] = imagecolorstotal( $this->image['render'] );
imagetruecolortopalette( $this->image['composite'], true, $this->image['colorcount'] );
imagepalettecopy( $this->image['composite'], $this->image['render'] );
$this->image['transparentcolor'] = imagecolortransparent( $this->image['render'] );
imagefill( $this->image['composite'], 0, 0, $this->image['transparentcolor'] );
imagecolortransparent( $this->image['composite'], $this->image['transparentcolor'] );
} else {
$this->image['composite'] = imagecreatetruecolor( $width, $height );
imagecopyresample( $this->image['composite'], $this->image['render'], 0, 0, 0, 0, $width, $height, $this->image['width'], $this->image['height'] );
}
} else {
echo 'Execution halted!';
}
}
public function proportion ( $max_width, $max_height ) {
if ( ! ( $this->halt ) ) {
if ( $this->image['extension'] == 'gif' ) {
$this->image['ratio'] = ( $this->image['width'] > $this->image['height'] ) ? $max_width / $this->image['width'] : $max_height/$this->image['height'];
if( $this->image['width'] > $max_width || $this->image['height'] > $max_height ) {
$new_width = $this->image['width'] * $this->image['ratio'];
$new_height = $this->image['height'] * $this->image['ratio'];
} else {
$new_width = $this->image['width'];
$new_height = $this->image['height'];
}
$this->image['composite'] = imagecreatetruecolor( $new_width, $new_height );
imagecopyresampled( $this->image['composite'], $this->image['render'], 0, 0, 0, 0, $new_width, $new_height, $this->image['width'], $this->image['height'] );
$this->image['colorcount'] = imagecolorstotal( $this->image['render'] );
imagetruecolortopalette( $this->image['composite'], true, $this->image['colorcount'] );
imagepalettecopy( $this->image['composite'], $this->image['render'] );
$this->image['transparentcolor'] = imagecolortransparent( $this->image['render'] );
imagefill( $this->image['composite'], 0, 0, $this->image['transparentcolor'] );
imagecolortransparent( $this->image['composite'], $this->image['transparentcolor'] );
} else {
$this->image['ratio'] = ( $this->image['width'] > $this->image['height'] ) ? $max_width / $this->image['width'] : $max_height/$this->image['height'];
if( $this->image['width'] > $max_width || $this->image['height'] > $max_height ) {
$new_width = $this->image['width'] * $this->image['ratio'];
$new_height = $this->image['height'] * $this->image['ratio'];
} else {
$new_width = $this->image['width'];
$new_height = $this->image['height'];
}
$this->image['composite'] = imagecreatetruecolor( $new_width, $new_height );
imagecopyresampled( $this->image['composite'], $this->image['render'], 0, 0, 0, 0, $new_width, $new_height, $this->image['width'], $this->image['height'] );
}
} else {
echo 'Execution halted!';
}
}
public function output ( $quality = 100 ) {
if ( ! ( is_numeric( $quality ) ) ) {
$quality = 100;
}
if ( ! ( $this->halt ) ) {
switch ( $this->image['extension'] ) {
case 'png';
header( 'Content-Type: image/png' );
imagepng( $this->image['composite'], null, null );
break;
case 'jpg';
header( 'Content-Type: image/jpeg' );
imagejpeg( $this->image['composite'], null, $quality );
break;
case 'jpeg';
header( 'Content-Type: image/jpeg' );
imagejpeg( $this->image['composite'], null, $quality );
break;
case 'gif';
header( 'Content-Type: image/gif' );
imagegif( $this->image['composite'], null, $quality );
break;
case 'bmp';
header( 'Content-Type: image/wbmp' );
imagewbmp( $this->image['composite'], null, null );
break;
case 'wbmp';
header( 'Content-Type: image/wbmp' );
imagewbmp( $this->image['composite'], null, null );
break;
}
} else {
echo 'Execution halted!';
}
}
public function saveto ( $destination, $filename, $quality = 100 ) {
if ( ! ( is_numeric( $quality ) ) ) {
$quality = 100;
}
if ( ! ( $this->halt ) ) {
switch ( $this->image['extension'] ) {
case 'png';
imagepng( $this->image['composite'], $destination . $filename . '.' . $this->image['extension'], null );
break;
case 'jpg';
imagejpeg( $this->image['composite'], $destination . $filename . '.' . $this->image['extension'], $quality );
break;
case 'jpeg';
imagejpeg( $this->image['composite'], $destination . $filename . '.' . $this->image['extension'], $quality );
break;
case 'gif';
imagegif( $this->image['composite'], $destination . $filename . '.' . $this->image['extension'], $quality );
break;
case 'bmp';
imagewbmp( $this->image['composite'], $destination . $filename . '.' . $this->image['extension'], null );
break;
case 'wbmp';
imagewbmp( $this->image['composite'], $destination . $filename . '.' . $this->image['extension'], null );
break;
}
} else {
echo 'Execution halted!';
}
}
public function clear_cache () {
imagedestroy( $this->image['composite'] );
imagedestroy( $this->image['render'] );
unset( $this->image );
unset( $this->s_image );
$this->halt = false;
}
}
?>
En dan in me .php bestand:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
// De ware grootte en hoogte ophalen
list($width, $height) = getimagesize($filename);
// In procenten weergeven, wat de kwaliteit moet worden
$quality = 80;
$Maxwidth = 1024; // Pixels (max hoogte)
$Maxheight = 1024; // Pixels (max hoogte)
// Als de afbeelding groter is dan hij mag zijn dan resizen
if($Maxwidth < $width || $Maxheight < $height)
{
$resizeimage = new ResizeImage();
$resizeimage->render( $filename );
$resizeimage->proportion( $Maxwidth, $Maxheight );
$resizeimage->saveto($map . '/', $TijdelijkebijlageZonder, $quality );
$resizeimage->clear_cache();
}
?>
// De ware grootte en hoogte ophalen
list($width, $height) = getimagesize($filename);
// In procenten weergeven, wat de kwaliteit moet worden
$quality = 80;
$Maxwidth = 1024; // Pixels (max hoogte)
$Maxheight = 1024; // Pixels (max hoogte)
// Als de afbeelding groter is dan hij mag zijn dan resizen
if($Maxwidth < $width || $Maxheight < $height)
{
$resizeimage = new ResizeImage();
$resizeimage->render( $filename );
$resizeimage->proportion( $Maxwidth, $Maxheight );
$resizeimage->saveto($map . '/', $TijdelijkebijlageZonder, $quality );
$resizeimage->clear_cache();
}
?>
Daar staat tiff niet tussen.. Dus die moet je daar toevoegen maar ook nog in de class zelf :-)
Het volgende toevoegen:
Code (php)
Ik heb op php.net gekeken, maar welke imagecreatefrom kan ik gebruiken voor tif en tiff :$ ?
Of is dat gewoon imagecreatefromtiff, als ik dat gebruik of imagecreatefromtif krijg ik de volgende error:
Fatal error: Call to undefined function imagecreatefromtif() in C:\Inetpub\wwwroot\mailmotortst\include\php\resizeimage.class.php on line 53
En dan in
Het volgende:
Code (php)
En welke kan ik gebruiken voor tiff en tif ipv imagepng? :$
En hier gewoon imagetiff?
Gewijzigd op 01/01/1970 01:00:00 door kitty N