http://www.shedlimited.debrucellc.com
このサイトでは、ユーザーは、phpスクリプト内の$ uploaded_imgに保存されているPHPスクリプト(ajaxupload.php)を介して画像をアップロードできます。新しく保存した画像のPATHをJSファイルに渡したいのですが、それを行う唯一の方法は、値をテキストファイルに書き込むことです。これは非常にやり過ぎです。
file_put_contents("testFile.txt", "");
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $upload_image;
fwrite($fh, $stringData);
$stringData = "\n";
fwrite($fh, $stringData);
fclose($fh);
同時に、html5Canvasなどをロードする外部.jsファイルを実行しています。
外部の.jsファイル内にグローバル変数sourcerを設定しました。これは、phpスクリプトでURLを書き込んだファイルからURLを読み取ることで、index.phpからアクセスして更新できます。
jQuery.get('scripts/testFile.txt', function(data) {
sourcer = data;
});
手動でテキストファイルに挿入せずにURL値をsourcerに渡す方法はありますか?