質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
CMS

CMS(Content Management System)は複数のユーザーでコンテンツを編集することが可能なWebサイトの管理/構築用のプラットフォームを指します。また、会社単位で運用管理するものはECMと呼びます。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Q&A

0回答

1909閲覧

<input type="file" name="" />がうまく反映されません。

ilovemathdayo

総合スコア14

CMS

CMS(Content Management System)は複数のユーザーでコンテンツを編集することが可能なWebサイトの管理/構築用のプラットフォームを指します。また、会社単位で運用管理するものはECMと呼びます。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

0グッド

1クリップ

投稿2017/01/28 15:31

編集2022/01/12 10:55

###前提・実現したいこと

Wordpressのプラグイン「buddypress」と「Advanced Custom Fields」を使い、
指定ユーザーが記事を投稿できるシステムを作成しています。

###発生している問題・エラーメッセージ
ユーザーのマイページから文章等は登録し、用意したページに反映されるのですが、
画像ファイルは上手くアップされず、困っております。

イメージページ http://misscampus-kadai.com/2016/01/14/syuukatusample/
実際のページ http://misscampus-kadai.com/store/%ef%bc%88%e6%a0%aa%ef%bc%89gakutopi%e3%80%80%e3%82%ac%e3%82%af%e3%83%88%e3%83%94/

このように実際のページでは画像が反映されておりません。

またユーザーの記事投稿画面は下記の画像の様になります。
![イメージ説明

そして下記がユーザーの記事投稿画面のソースコードの一部になります。

###該当のソースコード

/*--------------------------- * バリデーション *--------------------------*/ function check_postdata(){ global $post_error; global $upload_dir; global $image_url; if(!isset($_POST['title']) || empty($_POST['title'])){ $post_error[] = '販売店名が空白です。'; } if (isset($_FILES['image']['error']) && is_int($_FILES['image']['error'])) { // ファイルバリデーション if (!$_FILES['image']['error']) { // サイズ上限チェック if ($_FILES['image']['size'] > 100000) { $post_img_error[] = 'ファイルサイズが大きすぎます。'; } // getimagesizeを利用しMIMEタイプをチェック $imageInfo = getimagesize($_FILES['image']['tmp_name']); list($orig_width, $orig_height, $image_type) = $imageInfo; if ($imageInfo === false) { $post_error[] = '画像ファイルではありません。'; } else { $ext = substr($_FILES['image']['name'], strrpos($_FILES['image']['name'], '.') + 1); if (false === $ext = array_search( $imageInfo['mime'], array( 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif', ), true )) { $post_error[] = '画像形式が未対応です。'; } } $user = wp_get_current_user(); $upload_dir = wp_upload_dir(); $image_url = $upload_dir['path'] . '/'. $user->get('user_login').'-'. date(YmdHis) .'.'. $ext; if (!move_uploaded_file($_FILES['image']['tmp_name'],$image_url)) { $post_error[] = 'ファイル保存時にエラーが発生しました。'; } } } } function upload_image( $fname ){ global $post_id; if (isset($_FILES[$fname]['error']) && is_int($_FILES[$fname]['error'])) { // ファイルバリデーション if (!$_FILES[$fname]['error']) { $imageInfo = getimagesize($_FILES[$fname]['tmp_name']); list($orig_width, $orig_height, $image_type) = $imageInfo; if ($imageInfo === false) { // $post_img_error[] = '画像ファイルではありません。'; } else { $ext = substr($_FILES[$fname]['name'], strrpos($_FILES[$fname]['name'], '.') + 1); $user = wp_get_current_user(); $upload_dir = wp_upload_dir(); $image_url = $upload_dir['path'] . '/'. $user->get('user_login').'-'. date(YmdHis) .'.'. $ext; if (!move_uploaded_file($_FILES[$fname]['tmp_name'],$image_url)) { $post_img_error[] = 'ファイル保存時にエラーが発生しました。'; } } $filename = basename($image_url); if(wp_mkdir_p($upload_dir['path'])) $file = $upload_dir['path'] . '/' . $filename; else $file = $upload_dir['basedir'] . '/' . $filename; $image_data = file_get_contents($image_url); file_put_contents($file, $image_data); $wp_filetype = wp_check_filetype($filename, null ); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($filename), 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $file, $post_id ); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $file ); wp_update_attachment_metadata( $attach_id, $attach_data ); set_post_thumbnail( $post_id, $attach_id ); update_post_meta($post_id, $fname, $attach_id); } } } /*--------------------------- * エラーメッセージ表示セット *--------------------------*/ function show_post_error(){ global $post_error; if(!empty($post_error)){ echo '<div id="error">'; echo implode('<br />', $post_error); echo '</div>'; } } ?> <form action="<?php the_permalink();?>" method="post" enctype="multipart/form-data"> <input type="hidden" name="mode" id="mode" value="<?php echo $mode; ?>" /> <input type="hidden" name="id" id="id" value="<?php echo $post_id; ?>" /> <?php wp_nonce_field('store_regist'); ?> <table> <tr> <th>販売店名</th> <td><input type="text" name="title" id="title" class="" value="<?php echo $post->post_title; ?>" /></td> </tr> <tr> <th>トップイメージ</th> <td><input type="file" name="image" /></td> </tr> <tr> <th>企業イメージ</th> <td><input type="file" name="shoptopphoto" /></td> </tr> <tr> <th>アピール80文字</th> <td> <textarea type="text" name="appeal" id="appeal" class="" rows="5" style="width:98%;" /><?php echo $custom['appeal'][0]; ?></textarea> </td> </tr> <tr> <th>お店トップ画像</th> <td><input type="file" name="storephoto" /></td> </tr> <tr> <th>おすすめ画像①</th> <td><input type="file" name="storephoto1" /></td> </tr> <tr> <th>おすすめ画像①の説明(最大38文字) </th> <td> <textarea type="text" name="detail1" id="detail1" class="" rows="5" style="width:98%;" /><?php echo $custom['detail1'][0]; ?></textarea> </td> </tr>

投稿用スクリプトの一部になります。

<?php $custom = get_post_custom( $post->ID ); ?> <!-- shop --> <table style="width: 930px; height: 530px;" cellpadding="30"> <tbody> <tr style="height: 81px;"> <td style="border-color: #ffffff; width: 783px; height: 81px; text-align: center; vertical-align: top;" colspan="2"><?php if( get_field('shoptopphoto') ): ?><img src="<?php the_field('shoptopphoto'); ?>" width="920" /><?php endif; ?></td> </tr> <tr style="height: 81.19px;"> <td style="border-color: #ffffff; width: 391.03px; height: 81.19px; text-align: left; vertical-align: top;" colspan="2"><div class="wc-shortcodes-row wc-shortcodes-item wc-shortcodes-clearfix"><div class="wc-shortcodes-column wc-shortcodes-content wc-shortcodes-one-half wc-shortcodes-column-first "> <?php the_content(__('Read more', 'tcd-w')); ?> </div><div class="wc-shortcodes-column wc-shortcodes-content wc-shortcodes-one-half wc-shortcodes-column-last "> <span style="font-size: 14pt;"><img class="alignnone wp-image-3316" src="http://misscampus-kadai.com/wp-content/uploads/2016/01/キャプチャ_2017_01_14_14_25_41_972.png" alt="キャプチャ_2017_01_14_14_25_41_972" width="450" height="53" /></span> <span style="font-size: 14pt;"><strong>会社名:</strong><?php echo $post->post_title; ?></span><br/> <span style="font-size: 14pt;"><b> 住所 :</b><?php the_field('companyplace'); ?></span><br/> <span style="font-size: 14pt;"> <strong>代表者:</strong><?php the_field('代表者'); ?><strong> </strong></span><br/><span style="font-size: 14pt;"><b>資本金:</b><?php the_field('資本金'); ?><b><br/> 連絡先:</b><?php the_field('number'); ?><br/> <b>エントリーページ</b><br/><a href="<?php the_field('link'); ?>"><?php the_field('link'); ?></a></span><br/></div></div></td> </tr> </tbody> </table> <table style="width: 930px;" cellpadding="30"> <tbody> <tr> <td style="border-color: #ffffff; width: 437.46px; text-align: center;"><img class="alignnone size-full wp-image-2965" src="http://misscampus-kadai.com/wp-content/uploads/2017/01/キャプチャ_2017_01_15_01_04_24_259.png" alt="%e3%82%ad%e3%83%a3%e3%83%97%e3%83%81%e3%83%a3_2016_11_29_06_48_01_639" width="278" height="275" /></td> <td style="border-color: #ffffff; width: 437.46px; text-align: center;" rowspan="2"><?php if( get_field('storephoto') ): ?><img src="<?php the_field('storephoto'); ?>" width="380" /><?php endif; ?></td> </tr> <tr>

全く解決ができないため、ご教授していただけますと幸いです。
ではよろしくお願い致します。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2017/01/28 15:55

同じ質問を何度も投稿することは、私はマナー違反だと思うのですが、質問者様はどのように思われているのでしょうか。
ilovemathdayo

2017/01/28 15:59

内容を変更したため、いいと思い投稿してしまいました。初心者で同じ質問をしてしまい申し訳ございません。ただちに質問を消させていただきます。
退会済みユーザー

退会済みユーザー

2017/01/28 16:07

エラーログと、投稿用のスクリプトも含めてみないとわからない気がします。できればでいいので追記をおねがいします、
ilovemathdayo

2017/01/28 16:14

エラーログはわからなかったのですが、投稿用スクリプトの一部を追記いたしました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問