나는 관리자 패널에 업로드 된 뉴스를 표시하는 사이트를 만들고 있습니다.
각 게시물에는 이미지와 제목 (설명이 있지만 아직 구현하지 않았습니다)이 있습니다.
내 문제는 내가 게시하려고 할 때 (그리고 함께 이미지를 업로드 할 때) 게시물이 만들어 지지만 이미지가 존재하지 않는다는 것입니다.업로드 된 파일 (PHP)을 복사 할 수 없습니다.
업 로더 (PHP) :
if (isset($_FILES['image'])) {
//this script
//connects to mysql database
//declares an array that contains table names (array name is db)
require_once("db.php");
//move file to the img folder
move_uploaded_file($_FILES['image']['tmp_name'], "img/" . $_FILES['image']['tmp_name']);
//upload the post to the database
$sql = "INSERT INTO `{$db["posts"]}` (`img`, `text`) VALUES ('img/{$_FILES['image']['tmp_name']}', '{$_POST["text"]}')";
if (!mysql_query($sql)) {
//display error message
}
}
형태 (HTML)이 :
<form action="post.php" method="POST" enctype="multipart/form-data">
<label>Image: </label><input type="file" name="image" />
<br />
<label>Text: </label><input type="text" name="text" />
<input type="submit" />
</form>
내가 게시 한 후 FTP를 통해 파일을 확인, 이미지가 존재하지 않습니다.
[mysql_'] (http://stackoverflow.com/questions/12859942/why-shouldnt-i-ex-mysql-functions-in-php) 새 코드에서 데이터베이스 확장자를 사용할 때마다 * * [이런] (https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif) **는 사용되지 않으며 년간되어 왔으며 PHP7에서 영원히 사라 . PHP를 배우려는 분이라면'PDO' 또는'mysqli' 데이터베이스 확장과 prepared statement를 배우는 데 많은 시간을 할애하십시오. [여기에서 시작] (http://php.net/manual/en/book.pdo.php는) – RiggsFolly
스크립트는 [SQL 주입 공격]의 위험 (http://stackoverflow.com/questions/60174/how에있다 - 수 - 내가-방지-SQL 주입 -에 - PHP를) 에도 [당신이 입력을 탈출하는 경우, 그 안전하지!] (http://stackoverflow.com/questions/5741187/sql-injection-that-gets -around-mysql을 리얼 탈출 문자열) 사용 [매개 변수 제표를 작성 (http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly
는 PHP 파일 의 상단에 붙여 넣기 'ini_set ('display_errors', 1); ini_set ('display_startup_errors', 1); error_reporting (E_ALL); '오류를 확인하십시오. –