2012-03-28 3 views
0

time()을 사용하여 업로드 한 파일의 이름을 현재 시간으로 변경하고 싶습니다.하지만 새 시간 이름을 삽입 할 위치를 찾지 못하는 것 같습니다.Uploadify - 임시 이름을 시간으로 변경하고 업로드 - PHP

몇 사람이 이것을 살펴볼 수 있습니까?

<?php 
if (!empty($_FILES)) { 
    $newName = time(); <-- Should be the new temp name, insted of the uploaded one. 
    $tempFile = $_FILES['Filedata']['tmp_name']; 
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/'; 
    $targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']; 

    move_uploaded_file($tempFile,$targetFile); 
} 

echo '1'; 
?> 
+0

'$는 targetfile = 않는 str_replace ('//', '/', $있는 TargetPath)와 $_FILES['Filedata']['name']를 교체합니다. $ _FILES [ 'Filedata'] [ 'name']'이 줄 ... 필요하면 무엇이든 변경하십시오. $ _FILES [ 'Filedata'] [ 'name']'여기에서 변경하십시오 .. – Red

답변

1

$_FILES['Filedata']['name']이 당신의 이름을 가지고, 당신은 그것을 대체 할 수 있지만, 먼저 당신은 항상 동일 하 경우 파일의 확장자를 얻을 필요가있다.

$p = pathinfo($_FILES['Filedata']['name']); 
$newName = time() . "." . $p['extension']; 
$targetFile = str_replace('//','/',$targetPath) . $newName; 
+0

이것은 완벽하게 작동했습니다. , 고마워요 :) –

0
// Get the extension of the uploaded file .. 
$ext = end(explode('.', $_FILES['Filedata']['name'])); 
// Set the target location to your filename, plus the extension 
$targetFile = str_replace('//','/',$targetPath) . $newName . '.' . $ext; 
0

코드가 있어야한다 :

<?php 
if (!empty($_FILES)) { 
    $newName = time(); <-- Should be the new temp name, insted of the uploaded one. 
    $tempFile = $_FILES['Filedata']['tmp_name']; 
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/'; 
    $targetFile = str_replace('//','/',$targetPath) . $newName . '.EXT'; 

    move_uploaded_file($tempFile,$targetFile); 
} 

echo '1'; 
?> 
+0

이것은 잘 작동하지만, 난 그만 작동 확장명을 얻을 수 없습니다. xxx [ 'name'] [ 'extension'] 갈 수 있습니까? –

0

time()

관련 문제