2012-03-28 5 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'] 'ここから変更します.. – 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()

関連する問題