3 require_once('define.php');
5 function multiply_unit($str) {
6 $str = preg_replace('/(\d+)G/ei', "$1*1024*1024*1024", $str);
7 $str = preg_replace('/(\d+)M/ei', "$1*1024*1024", $str);
8 $str = preg_replace('/(\d+)K/ei', "$1*1024", $str);
9 $str = preg_replace('/(\d+)B/ei', "$1", $str);
12 $upload_max_filesize = ini_get('upload_max_filesize');
13 $upload_max_filesize_bytes = multiply_unit($upload_max_filesize);
15 function detect_image_ext(&$imagedata) {
16 $image_sig = substr($imagedata, 0, 0x10);
17 if (strpos($image_sig, 'JFIF') === 6) {
19 } elseif (strpos($image_sig, 'PNG') === 1) {
21 } elseif (strpos($image_sig, 'GIF') === 0) {
29 if (! empty($_FILES['imagefile']['tmp_name'])) {
30 $filename = $_FILES['imagefile']['tmp_name'];
31 $imagedata = file_get_contents($filename);
32 if ($imagedata > $upload_max_filesize_bytes) {
33 echo " $upload_max_filesize Bytes 以内のファイルしか受け付けません。\n";
36 $tmp_name = sha1($imagedata, false);
37 $id = $_REQUEST['id'];
38 $image_id = $_REQUEST['image_id'];
39 $ext = detect_image_ext($imagedata);
41 $image_sig = substr($imagedata, 0, 8);
42 echo "unknown image signature: ".bin2hex($image_sig)."\n";
45 $id_image = substr($tmp_name, 0, 16); // XXX
46 $tmp_filename = "$tmp_prefix$id_image$ext";
47 if ((! is_readable($tmp_filename)) &&
48 (! file_put_contents($tmp_filename, $imagedata))) {
49 fprintf(stderr, "swfimagereplace.php: file_put_contents failed. zero size?\n");
50 unlink($tmp_filename);
53 // header("Location: ./swfimagereplace.php?id=$id&image_id=$image_id&id_image=$id_image&ext=$ext");
57 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
59 <body bgcolor="#fff0f0">
60 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
61 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="100%" height="100%">
62 <param name="movie" value="./swfimagereplace.php?id=$id&image_id=$image_id&id_image=$id_image&ext=$ext">
63 <param name="quality" value="high">
71 if (empty($_REQUEST['id_image'])) {
72 $id = $_REQUEST['id'];
73 $image_id = $_REQUEST['image_id'];
77 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
79 <body bgcolor="#fff0f0">
80 <form enctype="multipart/form-data" action="" method="POST">
81 <input type="hidden" name="MAX_FILE_SIZE" value="$upload_max_filesize_bytes;
84 画像ファイルをアップロード: <input name="imagefile" type="file" />
85 <input type="hidden" name="id" value="$id" />
86 <input type="hidden" name="image_id" value="$image_id" />
87 <input type="submit" name="action" value="replace" />
89 ファイルを指定してください。($upload_max_filesize Bytes 以内に限定してます)
96 $id = $_REQUEST['id'];
97 $image_id = $_REQUEST['image_id'];
98 $id_image = $_REQUEST['id_image'];
99 $ext = $_REQUEST['ext'];
101 if (($ext != '.jpg') && ($ext != '.png') && ($ext != '.gif')) {
102 echo "unknown ext=($ext)..\n";
106 $swf_filename = "$tmp_prefix$id.swf";
107 $swfdata = file_get_contents($swf_filename);
108 $image_filename = "$tmp_prefix$id_image$ext";
109 $imagedata = file_get_contents($image_filename);
111 $swf = new SWFEditor();
112 $swf->setShapeAdjustMode(SWFEditor::SHAPE_BITMAP_RECT_RESIZE);
114 if ($swf->input($swfdata) == false) {
115 echo "input failed\n";
121 $result = $swf->replaceJpegData(intval($image_id), $imagedata);
124 $result = $swf->replacePNGData(intval($image_id), $imagedata);
127 $result = $swf->replaceGIFData(intval($image_id), $imagedata);
130 echo "unknown ext($ext)...\n";
134 if ($result == false) {
135 echo "replace failed ext=$ext\n";
139 header('Content-type: application/x-shockwave-flash');
140 // header('Content-type: application/octet-stream');