I have wrote this javascript code to upload files. The problem is it uploads all the files at the same time. I want to upload them one by one. I have been trying to do it for three hours.
$(document).ready(function() {
$(':file').change(function() {
$("#modsform").hide();
for (var i = 0; i < this.files.length; i++) {
var file = this.files[i];
showFile(file, i);
}
for (var i = 0; i < this.files.length; i++) {
var file = this.files[i];
sendFile(file, i);
}
});
});
full code:
http://jsfiddle.net/yhq83r6o/3/
Related
I am new to JavaScripting (have learned allot from this site!). I have existing code (from someone else) that successfully brings in all images into photoshop from a user selected folder. I would like to modify the code to only bring in specific file extensions (Jpg, png, tiff...etc). I found a great example of code from this site below of what I would like to do.
var distilledFileList = [];
for (var i = 0; i < fileList.length; i++){
if (/\.(?:jpe?g|png|gif|psd)$/i.test(fileList[i].name)){
distilledFileList.push(fileList[i]);
}
}
Original code found here
I have not figured out how to implement a version of this successfully into what I already have. Here is the main section of my code I believe where the modification needs to be added.
#target photoshop
app.bringToFront();
// Dialog for user to choose folder of documents to process
var inputFolderArray = [];
do {
var inputFolder = Folder.selectDialog("Select a folder of documents to process");
if(inputFolder != null) {
inputFolderArray.push(inputFolder);
}
}
while(inputFolder != null
|| inputFolder != undefined)
// Pulls images from inputFolder
for (var j = 0; j < inputFolderArray.length; j++) {
var filesList = inputFolderArray[j].getFiles();
var outputDirectory = inputFolderArray[j] + '/';
}
function PSDCreate(frameArrays, outputDirectory) {
directory = outputDirectory + '/';
//var outputLocation = inputFolder + "/" + directory;
var outputFileName = '';
if (frameArrays != null) {
// Get all the files in the folder
var fileList = frameArrays;
var k = 0;
for (var i = 0; i < fileList.length; i++) {
if (fileList[i] instanceof File && fileList[i].hidden == false) {
var fileName = fileList[i].name;
var docRef = open(fileList[i]);
if(k == 0) {
k++;
outputFileName = RemoveExtension(docRef.name);
app.displayDialogs = DialogModes.NO;
}
}
}
// Execute changes to images in photoshop here..
Does someone know how to implement a version of the example code to what I already have by chance? Any help is greatly appreciated!
If I understand correctly, you want user to select several folders and than process files of all these folders. First of all, here
// Pulls images from inputFolder
for (var j = 0; j < inputFolderArray.length; j++) {
var filesList = inputFolderArray[j].getFiles();
var outputDirectory = inputFolderArray[j] + '/';
}
filesList will be overwritten with every new folder, you'll get a list of files from the last folder selected only. I'd change this to
// Pulls images from inputFolder
var files = []
for (var j = 0; j < inputFolderArray.length; j++)
{
var filesList = inputFolderArray[j].getFiles();
for (var i = 0; i < filesList.length; i++)
{
if (/\.(?:jpe?g|png|gif|psd)$/i.test(filesList[i].name)) files.push(filesList[i]); //get needed files from folders
}
}
alert(files); // < array of files
if you only need to open these files, you can replace files.push(filesList[i]); with app.open(fileList[i]);
Hi I want to download a HTMl table to my pc
I manage to do it using sample code found on the net
This however download all the tables displayed
How do I specify which table i want to download
function exportTableToCSV(filename) {
var csv = [];
var rows = document.querySelectorAll("table tr");
for (var i = 0; i < rows.length; i++) {
var row = [], cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++)
row.push(cols[j].innerText);
csv.push(row.join(","));
}
// Download CSV file
downloadCSV(csv.join("\n"), filename);
}
function exportTableToCSV(tableNumber, filename) {
var csv = [];
var tables = document.querySelectorAll("table");
var rows = tables[tableNumber].querySelectorAll("tr");
for (var i = 0; i < rows.length; i++) {
var row = [], cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++)
row.push(cols[j].innerText);
csv.push(row.join(","));
}
// Download CSV file
downloadCSV(csv.join("\n"), filename);
}
}
Now you can input the table number that you want to download
I was wondering if it is possible to get this right. I am using a Jquery cropping tool (cropit). I am trying to put multiple file inputs into several cropper instances at once. Unfortunately it doesnt work that well.
For example, if I upload three images, the first two croppers are empty and the last one gets one of the images randomly. Here is the function:
function handleCropit(files) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
var count = counterCropit();
var reader = new FileReader();
reader.onload= function(e){ $('#image-cropper'+count).cropit('imageSrc', e.target.result);};
reader.readAsDataURL(file);
}
}
Figured it out!
function handleCropit(files) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
var count = counterCropit();
var croper = $('#image-cropper'+count);
var reader = new FileReader();
reader.onload= (function (yo) {return function(e){ yo.cropit('imageSrc', e.target.result);}})(croper);
reader.readAsDataURL(file);
}
}
Here is my code.
var cSharpButtons = document.getElementsByClassName("csharpbutton");
var jSButtons = document.getElementsByClassName("jsbutton");
var cSharp = document.getElementsByClassName("csharp");
var jS = document.getElementsByClassName("js");
function switchToCSharp()
{
for (i = 0; i < cSharpButtons.length; i++) //change button colors
{
cSharpButtons[i].style.backgroundColor = "#00AEEF";
}
for (i = 0; i < jSButtons.length; i++)
{
jSButtons[i].style.backgroundColor = "lightgrey";
}
for (i = 0; i < cSharp.length; i++) //change code
{
cSharp[i].style.display = "inline";
}
for (i = 0; i < jS.length; i++)
{
jS[i].style.display = "none";
}
}
function switchToJS()
{
for (i = 0; i < jSButtons.length; i++) //change button colors
{
jSButtons[i].style.backgroundColor = "#00AEEF";
}
for (i = 0; i < cSharpButtons.length; i++)
{
cSharpButtons[i].style.backgroundColor = "lightgrey";
}
for (i = 0; i < cSharp.length; i++) //change code
{
cSharp[i].style.display = "none";
}
for (i = 0; i < jS.length; i++)
{
jS[i].style.display = "inline";
}
}
GoDaddy said the permission were fine. Works like a charm on my desktop, they said something must be wrong with my code. They said it could be an outdated way of coding it.
nothing happens when you press a button, to try it for yourself visit http://spacehelmetstudios.com/tutorials/unity2d/directionalgravity2d/directionalgravity2d.html and try to change it from C# to JS.
I'm not going to lie, I don't know very much about the server side of things.
Any ideas? Thanks.
I know this isn't an answer, but in developers console I don't see any JS file downloaded and i get a console error saying that your functions are not defined. Maybe you forgot to add your JS files in your <head> tag?
When I select the files I want, I want to alert all the sizes together. So if I upload 3 files and on is 100bytes and one is 200 bytes and one is 500 bytes. I want it to alert 800 bytes. At the moment its alerting each one at a time.
This is the function
function upload(e){
e.preventDefault();
e.stopPropagation();
var file = document.getElementById("file");
for(var i = 0; i < file.files.length; i++){
var each = file.files[i];
var sizes = each.size;
alert(size);
}
startupload();
}
You were using alert inside the loop :
function upload(e){
e.preventDefault();
e.stopPropagation();
var file = document.getElementById("file"),
size = 0;
for(var i = 0; i < file.files.length; i++){
var each = file.files[i];
var sizes = each.size;
size += sizes;
}
alert(size);
startupload();
}