やりたいこと:入力ページ(index_test.php)からアップロードしたファイルをサーバー側のphpファイル(exec.php)で計算して、その計算結果を別タブ(output_page.php)で表示させたい。
以下のような機能をもったアプリケーションを開発しようとしています。
1.htmlから入力ファイルをアップロードして、それに対する計算ボタンを押す。
2.サーバー側のphpファイルで入力ファイルに対する計算結果であるans.txtと計算結果をダイアグラムで図示したoutput.bmpをサーバー内に出力
3.出力されたファイルを別タブの計算結果に表示させる。
現状:
index_test.php, exec.php, output_page.phpをXampp環境で動かして、以下の問題が起きる以外の場合は、結果が正しく表示することができる。
ディレクトリ情報
C:\xampp\htdocs\phpフォルダ直下にindex_test.php, exec.php, output_page.phpを設置
※exec.phpは、C:/xampp/htdocs/PycharmProjects/Web/cal.py"を実行している。
#困っていること:
1.入力が複雑な場合(?)、出力結果のphpファイルの表示が狂う。サーバー内に出力されたans.txtとoutput.bmpではなく、以前に表示した(?)ans.txtやoutput.bmpが表示されてしまうことがある。(優先度:高)
2.別ページへ遷移することしかできていない。できれば、別タブに新たに表示させたい。
#質問:
1.困っていること1に対する対応策をお教えいただけたら嬉しいです。
サーバー内で生成されたans.txtとoutput.bmpを正しく反映させたoutput_page.phpを表示させたいです。
現状でも、ほとんどの場合は表示できるのですが、おかしな表示をする場合があります。
2.別タブでoutput_page.phpを表示させる方法をお教えいただきたいです。ですが、とりあえずの急務としては、1の方が優先です。
以下にソースコードを添付します。
ソースコード
##index_test.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <div hidden> <FilesMatch ".html$"> AddType application/x-httpd-php .html </FilesMatch> </div> <html> <head> <title>GUI</title> <style type="text/css"> input.example1 { width: 45%; margin: 100 auto} input.example2 { width: 80%; margin: 0 auto} input.example3 { width: 250px; margin: 0 auto} input.example4 { width: 400px; margin: 0 auto} select { width: 250px; } textarea { width: 400px; height: 10em; } </style> <style> .display { display: none; } </style> <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> <meta http-equiv="CONTENT-TYPE" cont ent="text/html; charset=utf-8" /> <title>Object Test</title> </head> <body> <center> <h1>計算器</h1> </center> <center> <br> <br> <br> <br> <h1>ファイルをアップロード</h1> <form name="load" action="upload.php" method="post" enctype="multipart/form-data" id="sendMessageForm" target="sendMessage"> <p><input type="file" name="file" id="selfile"></p> <textarea name="txt" rows="10" cols="80" readonly></textarea> <p><input type="submit" value="選択したファイルをアップロード"></p> <iframe name="sendMessage" style="width:0px;height:0px;border:0px;"></iframe> <script> var obj1 = document.getElementById("selfile"); obj1.addEventListener("change",function(evt){ var file = evt.target.files; var reader = new FileReader(); reader.readAsText(file[0]); reader.onload = function(ev){ document.load.txt.value = reader.result; } },false); </script> </form> </center> <br> <br> <br> <br> <h1> STEP2: ファイルに対する計算</h1> <center> <form method="POST" action="exec.php" > <p><input type="submit" value="実行" class="example3"></p> </center> <br> <br> <br> <br> </body> </html>
## exec.php
<?php $command="C:/Users/usr/AppData/Local/Programs/Python/Python37-32/python C:/xampp/htdocs/PycharmProjects/Web/cal.py"; exec($command); header('Location: http://localhost/php/output_page.php' ) ; exit; ?>
output_page.php
<!DOCTYPE html> <html lang="ja"> <head> <title>出力</title> </head> <body> <h1>計算結果の表示</h1> <center> <div class="centering_item"> <OBJECT DATA="ans.txt" TYPE="text/plain" WIDTH="100%" HEIGHT="100%" alt="証明結果"></OBJECT> </div> </center> <br> <br> <br> <br> <br> <h1>計算結果のダイアグラムの表示</h1> <center> <p class="visualize"> <img src="output.bmp"> </p> </center> <style type="text/css"> .sample img { width: 70%; /* 横幅を割合で指定 */ height: auto; /* 高さは自動指定 */ } </style> </body> </html>



回答1件
あなたの回答
tips
プレビュー