2011-11-14 5 views
0

아래 코드로 서버의 디렉토리에 그림을 업로드하려고했습니다.업로드 된 파일을 옮길 때 오류가 발생했습니다.

경고 : 인 move_uploaded_file (이미지 /) [function.move 업로드 파일] 그러나, 내가 그것을 실행할 때, 나는이 오류 스트림을 열지 못했습니다 :/홈/a2943534/public_html이있는 디렉토리입니다 줄에 /add.php 24

경고 : 인 move_uploaded_file() [function.move 업로드 파일] :/홈/a2943534/public_html을 /에서 '이미지 /'에 '/ tmp를/php7yEkDe'을 이동할 수 없습니다 add.php on line 24

무엇을 놓치고 있습니까?

<?php 
include_once("connect.php"); 
?> 
<?php 

//This is the directory where images will be saved 
$target = "images/"; 
$target = $target . basename($_FILES['photo']['title']); 

//This gets all the other information from the form 
$title=$_POST['title']; 
$name=$_POST['name']; 
$describe=$_POST['describe']; 
$pic=($_FILES['photo']['title']); 
$url=$_POST['url']; 
$country=$_POST['country']; 
$endDate=$_POST['endDate']; 


//Writes the information to the database 
mysql_query("INSERT INTO `authors` VALUES ('$title', '$name', '$describe', '$pic', '$url', '$country', '$endDate')") ; 

//Writes the photo to the server 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
{ 

//Tells you if its all ok 
    $result = "The file ". basename($_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
} 
else { 

//Gives and error if its not 
$result = "Sorry, there was a problem uploading your file."; 
} 
?> 
<?php 
// if the form has been submitted, display result 
if (isset($result)) { 
    echo "<p><strong>$result</strong></p>"; 
    } 
?> 
+0

'images' 디렉토리가 실제로 존재하는지 확인하십시오. –

+0

또한'images' 디렉토리에 쓰기 권한이 있는지 확인하십시오. – JRSofty

+0

처음에는 위생 처리가 누락되어 임의의 파일 쓰기 취약점이 발생합니다. http://stackoverflow.com/questions/1911382/sanitize-file-path-in-php – Polynomial

답변

0

오히려

$target = $target . basename($_FILES['photo']['title']); 

를 작성하는 것보다 내가 $ _FILES [ '사진'] [ '제목']처럼 아무것도 생각

$target = $target . basename($_FILES['photo']['name']); 

를 작성해야 .. 그렇다

+0

감사합니다. 나는 그것을 바꿀 것이고 당신에게 돌아갈 것이다 – Kelvin

+1

고마워 이제 작동한다 :) – Kelvin

+0

나의 즐거움 .... :) –

0

난 당신이 제목이 아니라 $ _FILES [ '사진'] 내에 존재 않습니다이 때문에

$target = $target . basename($_FILES['photo']['name']); 

해야

$target = $target . basename($_FILES['photo']['title']); 

와 실수를 생각

또한이 오류 상태 :

Unable to move '/tmp/php7yEkDe' to 'images/' in /home/a2943534/public_html/add.php on line 24 

이미지/파일 이름이 없습니다.

0

오류는 분명하고 자명합니다.
두 번째 매개 변수는 파일명이어야하며 디렉토리가 아니어야합니다.

+0

파일 이름이 맞지 않나요? – Kelvin

+0

PHP는 폴더를 제공했다는 것을 분명히 말합니다 : "** 'images /'** '로 이동할 수 없습니다. 그렇지 않습니까? –

0

에서 여기에 MySQL이 포함되어있는 모든 PHP 질문에 나타나는 것처럼 보이는 SQL 삽입 문제는 디버깅을 시작해야합니다.

어떤 라인에서 어떤 오류가 발생하는지 명확하게 알 수 있습니다. Google에서 오류를 확인하려면 사용중인 기능에 대해 manual을 읽어보십시오.

짧은 이야기 : 두 변수를 만들고 함수 호출 전에 출력 한 다음 잘못된 것을 알아 내야합니다.

<?php 

$source = $_FILES['photo']['tmp_name']; 
$target = "images/" . basename($_FILES['photo']['title']); 

echo "Moving '$source' to '$target'"; 

move_uploaded_file($source, $target); 

오류가 발생한 곳을 즉시 확인할 수 있습니다.

+0

제발, 업로드 할 비트가있어,하지만 작동하도록 삽입을 얻을 수 없습니다. 제발 아무도 알지 못합니다 – Kelvin

+0

"디버깅 시작"부분에 대해 무엇을 얻지 못했습니까? :-) 귀하의 질의에 오류가있을 가능성이 큽니다. 인쇄하고, 분석하고, 작동 할 때까지 변경하십시오. 문서를보십시오. – CodeCaster

관련 문제