Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

php - Dropzone file upload new name?

Here is what my user interface looks like:

enter image description here

Here is my code. I want to change the file name when the file is uploaded.

index.html

<html>

<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />

<title>LCW DOSYA UPLOAD V1.0</title>
<link rel="stylesheet" href="dropzone.css"/>
<script src="dropzone.js"></script>
</head>
<body>
<center>
<label for="belge">Belge No:</label><br><br>
<input type="text" id="belge" name="belge"><br>
<br>
<input type="radio" id="ups" name="gender" value="ups">
<label for="ups">UPS</label><br>
<input type="radio" id="fillo" name="gender" value="fillo">
<label for="fillo">Fillo</label><br></center><br><br>

<form action="upload.php" class="dropzone" id="my-awesome-dropzone">

</form>

<script type="text/javascript">

Dropzone.options.myAwesomeDropzone = {
  paramName: "file", // The name that will be used to transfer the file
  maxFilesize: 20000, // MB
  renameFile: function (file) {
    let newName = new Date().getTime() + '_' + file.name;
    return newName;}
  };
</script>

</body>
</html>

upload.php

<?php

    $dizin="images/";
    $kaynak=$_FILES["file"]["tmp_name"];
    $hedef=$dizin.$_FILES["file"]["name"];
    
    if(move_uploaded_file($kaynak,$hedef)==true){
        echo 'Yukleme Basarili';
    }else {
        echo 'HATA';
    }


?>

The file name should be: belge + radio + 'filename.jpg'

What should I to make it should happen when I upload files?

question from:https://stackoverflow.com/questions/65862335/dropzone-file-upload-new-name

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
<script type="text/javascript">
    Dropzone.options.myAwesomeDropzone = {
        paramName: "file", // The name that will be used to transfer the file
        maxFilesize: 20000, // MB
        renameFile: function (file){
            var belge = document.getElementById('belge').value;
            
            var radios = document.getElementsByName('gender');
            for(var i = 0, length = radios.length; i < length; i++){
                if(radios[i].checked){
                    var radio = radios[i].value;
                }
            }
            
            let newName = belge + '_' + radio + '_' + file.name;
            return newName;
        }
    };
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...