ファイルを自分のサーバー上のフォルダにアップロードした後、パスをデータベーステーブルの列に保存するコードが見つかりました。フォームのコード:複数のファイルをアップロードする方法、フィールドを追加してデータベースへのフルパスを追加する方法
<form method="post" action="add_member.php" enctype="multipart/form-
data">
<p>Please Upload a Photo of the Member in gif or jpeg format. The file
name should be named after the Members name. If the same file name is
uploaded twice it will be overwritten! Maxium size of File is 35kb.
</p>
<p>
Photo:
</p>
<input type="hidden" name="size" value="350000">
<input type="file" name="cert_1">
<br/>
<br/>
<input TYPE="submit" name="upload" title="Add data to the
Database" value="Add Member"/>
</form>
そして、アップロードフォルダにファイルを移動して、データベースの列今
//This is the directory where images will be saved
$target = "upload";
$target = $target . basename($_FILES['cert_1']['name']);
//This gets all the other information from the form
$pic=($_FILES['cert_1']['name']);
// Connects to your Database
mysql_connect("host", "db_user", "_db_pass") or
die(mysql_error()) ;
mysql_select_db("your_db") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO student_biodata_master
(cert_1)
VALUES ('$pic')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['cert_1']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename($_FILES['cert_1']['name']). " has been
uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
への完全なパスを追加しますALGOでスクリプト、私がする必要がありますファイルのアップロードフィールドの数を少なくとも4つに増やしてから、ファイルのフルパスをそれぞれデータベース列に書き込んでください。スクリプトはうまく動作しますが、データベースに完全なパスを書き込むことはできません。後で呼び出すことができ、アプリケーションに表示することができます。 「anygoodbody」はこれを手伝うことができますか?実際に私の頭の中でやっている。
いつも大きなアドバイスをお寄せいただきありがとうございます。
スタックオーバーフローの岩!
あなたは[sql injection attacks](http://bobby-tables.com)に脆弱です。 –
これはここに答えていますhttp://stackoverflow.com/questions/2704314/multiple-file-upload-in-php – Emma
**警告**:PHPを学んでいるだけの方は、[mysql_query '](http://php.net/manual/en/function.mysql-query.php)インターフェイス。それはPHP 7で削除されたのでとてもひどいと危険です。[PDOのようなものは学ぶのが難しくない](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps -pdo-for-database-access /)と[PHP The Right Way](http://www.phptherightway.com/)のようなガイドがベストプラクティスを説明しています。あなたのユーザーパラメータは**適切にエスケープされていません**(http://bobby-tables.com/php)、悪用可能な[SQLインジェクションバグ](http://bobby-tables.com/)があります。 – tadman