2012-07-08 3 views
0

HTML 폼에서 파일을 업로드하기 위해 PHP 스크립트를 실행하고 이름을 바꾸어 내 서버에 저장하십시오. 업로드하고 이름을 바꾸는 중이지만 모든 파일 이름은 이제 "Array"라는 단어로 시작됩니다.
예 : ArrayTest Document v1.0.pdf
테이블에 표시 할 때 그 문자가 내 $newfn이 아닌 것으로 확신합니다. 그것이 move_uploaded_file 명령을 내 $FILES['uploaded'] 섹션에 관련된 것처럼업로드 후 이름이 바뀐 파일 이름 앞에 ARRAY가 있습니다 - PHP

//This gets all the other information from the form 
$name=$_POST['docname']; 
$version=$_POST['docver']; 
$date=$_POST['docdate']; 
$type=$_POST['doctype']; 
$author=$_POST['docauth']; 
$file=$_FILES['uploaded']['name']; 

//target directory is assigned 
$target = $directory; 
$target = $target . basename($file) ; 

//grab file extension 
$filetypes = array(
'image/png' => '.png', 
'image/gif' => '.gif', 
'image/jpeg' => '.jpg', 
'image/bmp' => '.bmp', 
'application/pdf' => '.pdf'); 
$ext = $filetypes[$_FILES['uploaded']['type']]; 

//generate new filename variable "name v??.xxx" 
$newfn = $name . ' ' . 'v' . $version . $ext; 

//Check to see if file exists 
if (file_exists($directory . $file)) 
{ 
echo $_FILES["uploaded"]["name"] . " already exists. "; 
} 
else 
{ 
//if its a new file, change name and upload 
    if (move_uploaded_file($_FILES["uploaded"]["tmp_name"], 
     $directory . $_FILES["uploaded"] . $newfn)) 
     { 
     echo "The file ". basename($file). " has been uploaded"; 
     } 
     else 
     { 
     echo "Sorry, there was a problem uploading your file."; 
     } 
} 

는 느낌. 검색 좀 해봤지만 "배열"이라고 말하면 Google 검색 결과는 원격으로 동일하지 않습니다.

좋아, 아래 덕분에 해결했습니다. 모든 이제 올바른 이름 구조 업로드

//if its a new file, change name and upload 
if (move_uploaded_file($_FILES["uploaded"]["tmp_name"], 
    $directory . $newfn)) 

로 코드를 읽기 때문에 미래에 누군가를 위해 내가 전체 $_FILES 배열을 제거했습니다. 감사.

+1

$ _FILES [ "uploaded"]이 (가) 배열이므로 showas 배열입니다. –

답변

0

당신은 포함 깜빡

move_uploaded_file($_FILES["uploaded"]["tmp_name"],$directory . $_FILES["uploaded"]["name"] . $newfn) 

이어야한다 [ "이름"] 후 $ _FILES [ "업로드"] 당신의 인 move_uploaded_file에서

+0

만약'[ "name"]'새로운 이름 앞에 원래의 문서 이름을 붙이면'Original Document.pdf'가 'Original Document.pdfNew Document.pdf' – Hux

+0

이됩니다. 단지 새로운 Document.pdf 만 원한다면 $ _FILES [ "uploaded"] [ "name"]을 포함 할 이유가 없습니다. 그냥 $ 디렉토리로 만드십시오. $ newfn –

0

당신은 이름으로 단지를 전체 $_FILE['uploaded'] 배열을 사용하는 파일명. 작은 조정 :

if (move_uploaded_file($_FILES["uploaded"]["tmp_name"], 
     $directory . $_FILES["uploaded"]["name"] . $newfn)) 
     { 

그리고 모두 잘해야합니다.

관련 문제