Вход Регистрация
Файл: adultscript-2.0.3-pro/files/mobile/templates/default/photo_add.tpl.php
Строк: 137
<?php defined('_VALID') or die('Restricted Access!'); ?>
    <script type="text/javascript">
    var extensions = /<?php echo '(',implode('|',$this->pcfg['photo_allowed_ext']),')'?>/i;
    function fileSelected() {
        var count = document.getElementById('fileToUpload').files.length;
        
        document.getElementById('details').innerHTML = "";
        for (var index = 0; index < count; index ++)
        {
              var file         = document.getElementById('fileToUpload').files[index];
              var filename    = file.name;
            ext             = filename.slice(filename.indexOf(".")).toLowerCase();
              if (!ext.match(extensions)) {
                $("#errors").html("<h3>Invalid file extension! Allowed extensions: <?php echo implode(', '$this->pcfg['photo_allowed_ext']); ?></h3>");
                $("#errors").show();
                return;
              }
          
              if (file.size > <?php echo $this->pcfg['photo_max_size']*1024*1024?>) {
                  $("#errors").html("<h3>File exceeds the maximum allowed filesize limit of <?php echo $this->pcfg['photo_max_size']; ?>MB!</h3>");
                  $("#errors").show();
                  return;
              }

              var fileSize = 0;
              if (file.size > 1024 * 1024) {
                  fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
              } else {
                fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
              }

              document.getElementById('details').innerHTML += 'Name: ' + file.name + '<br>Size: ' + fileSize + '<br>Type: ' + file.type;
              document.getElementById('details').innerHTML += '<p>';
        }
    }

    function uploadFile() {
        var fd = new FormData();
        var count = document.getElementById('fileToUpload').files.length;
        for (var index = 0; index < count; index ++)
        {
              var file = document.getElementById('fileToUpload').files[index];
            fd.append('myFile' + index, file);
        }

        var xhr = new XMLHttpRequest()
        xhr.upload.addEventListener("progress", uploadProgress, false);
        xhr.addEventListener("load", uploadComplete, false);
        xhr.addEventListener("error", uploadFailed, false);
        xhr.addEventListener("abort", uploadCanceled, false);
        xhr.open("POST", "<?php echo MOBILE_REL?>/ajax.php?s=photo_upload&d=mobile&unique=<?php echo $this->unique?>");
        xhr.send(fd);
    }
    
    function uploadProgress(evt) {
        if (evt.lengthComputable) {
          var percentComplete = Math.round(evt.loaded * 100 / evt.total);
          $("#progress").show();
          $("#slider").val(percentComplete.toString());
          $("#slider").slider('refresh');
        } else {
          document.getElementById('progress').innerHTML = 'unable to compute';
        }
    }
    
    function uploadComplete(evt) {
        $("#photo-upload-form").submit();
    }
    
    function uploadFailed(evt) {
        alert("There was an error attempting to upload the file.");
    }
    
    function uploadCanceled(evt) {
        alert("The upload has been canceled by the user or the browser dropped the connection.");
    }    
    </script>
    <div data-role="content">
        <br>
        <ul data-role="listview">
            <li data-role="list-divider"><?php echo __('add-photos'); ?></li>
        </ul>
        <br>
        <br>
        <form id="photo-upload-form" method="post" enctype="multipart/form-data"  action="<?php echo MOBILE_REL?>/photo/add/<?php echo $this->album['album_id']; ?>">
            <input name="upload_id" type="hidden" value="<?php echo $this->unique?>">
            <input name="upload-submitted" type="hidden" value="1">
            <label for="guidelines"><strong><?php echo __('guidelines'); ?></strong>:</label>
            <p><?php echo __('photo-add-guidelines-text'); ?></p>            
            <label for="fileToUpload"><?php echo __('file'); ?>:</label>
            <input type="file" name="fileToUpload" id="fileToUpload" onchange="fileSelected();" accept="image/*" capture="camera" multiple="multiple" />
            <div id="errors" class="ui-bar ui-bar-d red" style="display: none;"></div>
            <div id="details"></div>
            <div id="progress" style="display: none;">
                <input type="range" name="slider" id="slider" data-highlight="true" min="0" max="100" value="0">
            </div>
            <button type="button" data-theme="b" name="submit-upload" onclick="uploadFile();"><?php echo __('add-photos'); ?></button>
        </form>
    </div>
Онлайн: 0
Реклама