0 レビュー
0 回答
php-画像はアップロードされますが、データベースには何も追加されませんか?
phpで単純な画像アップロード機能を作成しようとしていますが、何らかの理由でタスクが完了しません。 URLが*/action.php
の白い画面で動かなくなり、そのページでエラーが発生することもあれば、何も表示されないこともあります(現時点では)。
それが重要な場合、私はXAMPPを介して作業しています。
(プリペアドステートメントが不足していることを認識しています)
action.php :
$target_directory = "/Applications/XAMPP/xamppfiles/htdocs/uploads/";
$filename = $_POST['fileLocation'];
$temp_filename = $_FILES["file"]["tmp_name"];
$size = $_FILES["file"]["size"];
// Produce a unique filename
$randomNumber = time();
$filetype = substr($filename, strrpos($filename, '.'));
$target_file = $target_directory . $randomNumber . $filetype;
$local_path = "/Applications/XAMPP/xamppfiles/htdocs/uploads/" . $randomNumber . $filetype;
header('Content-type: text/html; charset=utf-8');
if(!move_uploaded_file($temp_filename, $target_file))
header( 'localhost/index.php', 301 );
// = = = = Add to database = = = =
$conn = mysql_connect("localhost", "root", "") or die(mysql_error());
$db = mysql_select_db("gps");
// Collect data from form
$imagetext = $_POST["imagetext"];
$locationstring = $_POST["locationstring"];
$query = "INSERT INTO gps (imagetext, file, locationstring) VALUES ('$imagetext', '$local_path','$locationstring')";
mysql_query($query);
mysql_close();
header( 'localhost/index.php', 301 );
エラーは次のように切り替わります:
警告:move_uploaded_file(/uploads/images/1495626347.psd):ストリームを開くことができませんでした:20行目の/Applications/XAMPP/xamppfiles/htdocs/action.phpにそのようなファイルまたはディレクトリはありません
+
警告:move_uploaded_file():オンラインの/Applications/XAMPP/xamppfiles/htdocs/action.phpの「/Applications/XAMPP/xamppfiles/temp/phpYsJkjq」を「/uploads/images/1495626347.psd」に移動できません20
および
警告:ファイルアップロードエラー-0行目の不明に一時ファイルを作成できません
ただし、ファイルはローカルにあるべき場所にあります。
HTML(誰かが見てみたい場合):
<form method="POST" action="action.php" enctype="multipart/form-data"> <input id="fileLocation" name="fileLocation" type="text" class="form-control" placeholder="Image to upload" style="display:none"> <button type="button" value="Browse..." id="browseBtn" class="title">Select files...</button> <input type="hidden" name="locationstring" style="display:none;"/> <input type="file" name="file" id="hiddenFile" style="display: none;"/> <input id="content" name="imagetext" class="form-control" type="text" placeholder="Text Below Image"/> <input type="submit" value="Upload" name="submit"> </form>
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。