我检查了stackoverflow,但在这里找不到答案:
1)将ID2格式化为“000000”六位数,例如如果ID2为302那么应该是000302
2)我想将现在格式化的数据(000302)与upload.php文件中的。$ _ FILES ['file'] ['name']组合在一起,并使用这个新文件名保存文件。
我真的迷失了怎么做。
文件传输代码不是来自我。这是来自互联网的代码。
我会很乐意提供任何帮助!
这是头部分:
<script type="text/javascript" src="js/multiupload.js"></script>
<script type="text/javascript">
var config =
{
support : "image/jpg,image/png,image/bmp,image/jpeg,image/gif", // Valid file formats
form: "demoFiler", // Form ID
dragArea: "dragAndDropFiles", // Upload Area ID
uploadUrl: "upload.php" // Server side upload url
}
$(document).ready(function(){
initMultiUploader(config);
});
</script>
这在身体部分:
<div id="dragAndDropFiles" class="uploadArea">
<br>
<span style="padding-left: 20px">To upload more pictures for this item click Browse</span>
<br>
<span style="padding-left: 20px">The order of the upload decide the order to show the pictures</span>
</div>
<form name="demoFiler" id="demoFiler" enctype="multipart/form-data" style="">
<input id="ID2" type="hidden" name="ID2">
<input type="file" name="multiUpload" id="multiUpload" multiple />
<input type="submit" name="submitHandler" id="submitHandler" value="Upload" class="buttonUpload" />
</form>
<div class="progressBar">
<div class="status"></div>
</div>
这是文件upload.php
<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){
if(move_uploaded_file($_FILES['file']['tmp_name'], "sobimages/".$_FILES['file']['name'])){
echo($_POST['index']);
}
exit;
}
?>
答案 0 :(得分:1)
您可以使用sprintf
功能转换为所需的位数。例如。你可以在upload.php
:
if($_SERVER['REQUEST_METHOD'] == "POST"){
$new_id = sprintf( "%06d", $_POST['ID2']);
if(move_uploaded_file($_FILES['file']['tmp_name'], "sobimages/" . $new_id . $_FILES['file']['name'])){
echo($_POST['index']);
}
exit;
}