ファイル名をMySQLにリンクする必要があるPHPを使用してフォルダーに画像をアップロードするスクリプトを作成しました。
長い一日を過ごした後、見えないものを見逃したと思います:(
アップロード.php
<form enctype="multipart/form-data" action="add.php" method="POST">
Photo: <input type="file" name="images"><br>
<input type="submit" value="Add">
</form>
add.php
<?php
error_reporting(E_ALL);
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['images']);
//This gets all the other information from the form
$images=($_FILES['images']);
// Connects to your Database
mysql_connect("localhost", "root", "pass") or die(mysql_error()) ;
mysql_select_db("formular") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$images')") ;
//Writes the pictures to the server
if(move_uploaded_file($_FILES['images']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']). " 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.";
}
?>
view.php
<?php
// Connects to your Database
mysql_connect("localhost", "root", "pass") or die(mysql_error()) ;
mysql_select_db("formular") or die(mysql_error()) ;
//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM employees") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
//Outputs the image and other data
Echo "<img src=images/".$info['images'] ."> <br>";
}
?>
全然thx