Skip to content

Commit 96a37e2

Browse files
committed
Update to 0.2.0
Fix bugs
1 parent 1156dc9 commit 96a37e2

File tree

4 files changed

+120
-14
lines changed

4 files changed

+120
-14
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Date: 2025-5-16
44
Author: various authors
55
Maintainer: Yu Hongbo <[email protected]>, CNOCTAVE <[email protected]>
66
Title: Octave FFmpeg Free
7-
Description: The octave_php_wrapper package creates a PHP wrapper for Octave
8-
script, so that you can run the Octave script by PHP,
9-
like modern Internet service.
7+
Description: The octave_php_wrapper package creates a PHP wrapper for Octave
8+
script, so that you can run the Octave script by PHP,
9+
like modern Internet service.
1010
Depends: octave (>= 5.2.0)
1111
License: GPLv3+
1212
Url: https://github.com/CNOCTAVE/octave_php_wrapper

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
** v0.2.0
2+
Fix bugs
3+
-------------------------------------------------------
14
** First release.

docs/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@
367367
<pre><code class="php">&lt;?php
368368
if ($_SERVER['REQUEST_METHOD'] === 'DELETE') {
369369
parse_str($_SERVER['QUERY_STRING'], $queryParams);
370-
371370
if (isset($queryParams['n'])) {
372371
$n = $queryParams['n'];
373372
echo escapeshellarg($n);

inst/octave_php_wrapper_examples.m

Lines changed: 114 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,130 @@
5757
"?>",
5858
};
5959
elseif strcmp(name, "pass_args_post") == 1
60-
octave_php_wrapper_example_string = pass_args_post();
60+
text_cell = {
61+
"<?php",
62+
"if (isset($_POST['n'])) {",
63+
" $n = $_POST['n'];",
64+
" echo escapeshellarg($n);",
65+
"} else {",
66+
" echo \"Param n should not be null.\";",
67+
"}",
68+
"?>",
69+
};
6170
elseif strcmp(name, "pass_args_put") == 1
62-
octave_php_wrapper_example_string = pass_args_put();
71+
text_cell = {
72+
"<?php",
73+
"if ($_SERVER['REQUEST_METHOD'] === 'PUT') {",
74+
" $n = file_get_contents('php://input');",
75+
" echo escapeshellarg($n);",
76+
"} else {",
77+
" echo \"This script only handles PUT requests.\";",
78+
"}",
79+
"?>",
80+
};
6381
elseif strcmp(name, "pass_args_patch") == 1
64-
octave_php_wrapper_example_string = pass_args_patch();
82+
text_cell = {
83+
"<?php",
84+
"if ($_SERVER['REQUEST_METHOD'] === 'PATCH') {",
85+
" $n = file_get_contents('php://input');",
86+
" echo escapeshellarg($n);",
87+
"} else {",
88+
" echo \"This script only handles PATCH requests.\";",
89+
"}",
90+
"?>",
91+
};
6592
elseif strcmp(name, "pass_args_delete") == 1
66-
octave_php_wrapper_example_string = pass_args_delete();
93+
text_cell = {
94+
"<?php",
95+
"if ($_SERVER['REQUEST_METHOD'] === 'DELETE') {",
96+
" parse_str($_SERVER['QUERY_STRING'], $queryParams);",
97+
" if (isset($queryParams['n'])) {",
98+
" $n = $queryParams['n'];",
99+
" echo escapeshellarg($n);",
100+
"} else {",
101+
" echo \"Param n should not be null.\";",
102+
" }",
103+
"} else {",
104+
" echo \"This script only handles DELETE requests.\";",
105+
"}",
106+
"?>",
107+
};
67108
elseif strcmp(name, "jsondecode") == 1
68-
octave_php_wrapper_example_string = jsondecode();
109+
text_cell = {
110+
"args = argv();",
111+
"n = jsondecode(args(1));",
112+
"disp(sum(n));",
113+
};
69114
elseif strcmp(name, "jsonencode") == 1
70-
octave_php_wrapper_example_string = jsonencode();
115+
text_cell = {
116+
"n = [1,2,3,4,5,6,7];",
117+
"disp(jsonencode(n));",
118+
};
71119
elseif strcmp(name, "base64_decode") == 1
72-
octave_php_wrapper_example_string = base64_decode();
120+
text_cell = {
121+
"args = argv();",
122+
"n = base64_decode(args(1));",
123+
"disp(sum(n));",
124+
};
73125
elseif strcmp(name, "base64_encode") == 1
74-
octave_php_wrapper_example_string = base64_encode();
126+
text_cell = {
127+
"n = [1,2,3,4,5,6,7];",
128+
"disp(base64_encode(n));",
129+
};
75130
elseif strcmp(name, "upload_file") == 1
76-
octave_php_wrapper_example_string = upload_file();
131+
text_cell = {
132+
"<?php",
133+
"if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['fileToUpload']) && $_FILES['fileToUpload']['error'] == UPLOAD_ERR_OK) {",
134+
" $fileTmpPath = $_FILES['fileToUpload']['tmp_name'];",
135+
" $fileName = $_FILES['fileToUpload']['name'];",
136+
" $fileSize = $_FILES['fileToUpload']['size'];",
137+
" $fileType = $_FILES['fileToUpload']['type'];",
138+
" $fileNameCmps = explode(\".\", $fileName);",
139+
" $fileExtension = strtolower(end($fileNameCmps));",
140+
" $allowedfileExtensions = array('jpg', 'jpeg', 'png', 'gif');",
141+
" if (in_array($fileExtension, $allowedfileExtensions)) {",
142+
" $uploadFileDir = 'uploads/';",
143+
" if (!is_dir($uploadFileDir)) {",
144+
" mkdir($uploadFileDir, 0777, true);",
145+
" }",
146+
" $dest_path = $uploadFileDir . $fileName;",
147+
" if(move_uploaded_file($fileTmpPath, $dest_path)) {",
148+
" echo \"File is valid and was successfully uploaded.\n\";",
149+
" } else {",
150+
" echo \"There was some error moving the file to upload directory. Please make sure the upload directory is writable.\";",
151+
" }",
152+
" } else {",
153+
" echo \"Sorry, only JPG, JPEG, PNG & GIF files are allowed.\";",
154+
" }",
155+
"} else {",
156+
" echo \"No file was uploaded. Sorry, your file was not uploaded.\";",
157+
"}",
158+
"?>",
159+
};
77160
elseif strcmp(name, "download_file") == 1
78-
octave_php_wrapper_example_string = download_file();
161+
text_cell = {
162+
"<?php",
163+
"$filePath = 'path/to/your/file.zip';",
164+
"if (!file_exists($filePath)) {",
165+
" die('File not found');",
166+
"}",
167+
"$fileSize = filesize($filePath);",
168+
"header('Content-Description: File Transfer');",
169+
"header('Content-Type: application/octet-stream');",
170+
"header('Content-Disposition: attachment; filename=\"' . basename($filePath) . '\"');",
171+
"header('Content-Transfer-Encoding: binary');",
172+
"header('Expires: 0');",
173+
"header('Cache-Control: must-revalidate');",
174+
"header('Pragma: public');",
175+
"header('Content-Length: ' . $fileSize);",
176+
"ob_clean();",
177+
"flush();",
178+
"readfile($filePath);",
179+
"exit;",
180+
"?>",
181+
};
79182
else
80183
error('name must be one of the supported examples.');
184+
endif
81185
octave_php_wrapper_example_string = strjoin(text_cell, "\n");
82186
endfunction

0 commit comments

Comments
 (0)