저와 같은 초보자를 돕는 데 감사드립니다. 다음과 같은 문제가 있으며 긴급한 도움을받을 것입니다.그림을 서버에 성공적으로 업로드하지만 데이터베이스에 파일 이름을 공백으로 넣으십시오.
문제 번호 1 : PHP와 MySQL을 사용하면 양식의 다른 매개 변수가 데이터베이스에 successfuly 삽입되었지만 그림의 파일 이름이 아니라 서버에 그림을 성공적으로 업로드 할 수 있습니다. 이 사이트에서이 주제를 포함하여 여러 게시물을 읽었지만 아직 문제를 해결할 수 없습니다.
문제 번호 2 : 파일 SIZE (100kb 이하)뿐만 아니라 업로드 (gif, jpeg, png에만 해당) 제한된 파일 TYPE에 대한 도움이 필요합니다.
문제 번호 3 : 작은 그림 축소 그림 크기 20kb로 업로드 된 모든 그림의 크기를 강제로 변경하고 서버의 별도 폴더에이 파일을 별도의 파일 이름으로 저장합니다.
아래는 현재 PHP 코드입니다.
<?php
if (!isset($_POST['upload']))
{
include ("submit_interview_test.php"); //shows form if it's not been posted
}
else
{
if($_FILES['pic']['tmp_name'] == "none")
{
echo "<b>File not successfully uploaded. Maybe check the filesize limit.</b>";
include ("submit_interview_test.php");
exit();
}
if(!ereg("image",$_FILES['pic']['type']))
{
echo "<b>File is not an image - try another file.</b>";
include ("submit_interview_test.php");
exit();
}
else
{
$uploadDir = 'intervimages/';
$destination = $uploadDir.basename($_FILES['pic']['name']);
$temp_file = $_FILES['pic']['tmp_name'];
include ("processinterview.php");
if (move_uploaded_file ($temp_file,$destination))
{ echo '<p>Your file has been successfully uploaded!</p>';
}
else
{ echo "Problem with picture upload!";
}
} // end of else
} // end of else
?>
이것은 내 processinterview.php 코드입니다.
<?php
include_once 'includes/db.php';
$sql="INSERT INTO interview (interviewer, media_house, category, interview_title, title_rider, personality, interview_body, source, published, temp_file, interview_date, location, interview_intro, date) VALUES ('$_POST[interviewer]','$_POST[media_house]','$_POST[category]','$_POST [interview_title]','$_POST[title_rider]','$_POST[personality]','$_POST [interview_body]','$_POST[source]','$_POST[published]','$_FILES[temp_file]','$_POST[interview_date]','$_POST[location]','$_POST[interview_intro]',now())";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
echo "1 interview record has been successfully added to the database.";
?>
그리고 이것은 내 양식 (submit_interview_test.php)입니다.
<form enctype="multipart/form-data" action="processinterview3.php" method="post">
<table bgcolor="#ececec" border="0" cellspacing="5">
<tbody>
<tr><td>Interview conducted by (Interviewer's Name):</td><td><input size="30" name="interviewer" type="text" /></td></tr>
<tr><td>Media house (e.g., Punch):</td><td><input size="30" name="media_house" type="text" /></td></tr>
<tr><td>Location (e.g., Ibadan or USA):</td><td><input type="text" size="30" name ="location" /></td></tr>
<tr><td>Interview Category (e.g., Local):</td><td><input type="text" size="30" name ="category" /></td></tr>
<tr><td>Interview Personality:</td><td><input type="text" size="30" name ="personality" /></td></tr>
<tr><td>Interview Title:</td><td><input type="text" size="130" name ="interview_title" /></td></tr>
<tr><td>Title Rider:</td><td><input type="text" size="130" name ="title_rider" /></td></tr>
<tr><td>Source (e.g., http://...):</td><td><input size="130" name="source" type="text" /></td></tr>
<tr> <td valign="top">Interview Introduction:</td>
<td><textarea name="interview_intro" rows="3" cols="100"></textarea></td></tr>
<tr><td>Date of Interview (e.g., 26/09/2009):</td><td><input size="30" name="interview_date" type="text" /></td></tr>
<tr> <td valign="top">Interview Main Content:</td>
<td><textarea name="interview_body" rows="12" cols="100"></textarea></td></tr>
<tr><td>Add Photo (Jpeg or gif not more than 80KB):</td><td><input type="file" name="pic"/></td></tr>
<tr><td valign="top">Publish rightaway?</td>
<td><input type="checkbox" name="published" value="1"> Yes (Leave this if this Interview is not to be published yet)<br>
<tr><td> </td><td><input value="Submit Interview" type="submit" name="upload"/><font face="arial" size="1"> Please check for any error before you submit</font></td></tr>
</tbody></table>
고맙습니다. pls.
감사의 말을 Cryo에게 보내주십시오. 제 코드에서 $ _FILE [temp_name]을 보지 못해서 처리 코드 (processinterview.php)에서 $ _FILE [temp_file]을 보았습니다. 이 파일을 $ temp_file로 변경했습니다. ($ _FILE [temp_file]을 대체합니다.) 사실, 이번에는 데이터베이스에서 값을 얻었지만 실제 파일 이름이 아닌/tmp/php4hY4er,/tmp/phppUzQbA 등의 파일은 이해할 수 없습니다. – user249399
/tmp/php4hY4er는 서버의 임시 파일입니다. 영구적으로 복사하여 그 파일 이름을 저장해야합니다. – James
업로드 된 원본 파일의 이름으로 $ _FILES [ 'pic'] [ 'name']을 사용하십시오. – nortron