PageSourceSearch

http://futuretechbizsoft.com/Js/UploadFile.js

js futuretechbizsoft.com collected 2026-10-02 01:29:50 UTC 17,445 bytes, 488 lines download raw bytes

1// check extension of file to be upload
2
3function checkFileExtension(file) {
4    var flag = true;
5    var extension = file.substr((file.lastIndexOf('.') + 1)).toUpperCase();
6    
7    switch (extension) {
8        case 'JPG':
9        case 'JPEG':
10        case 'PNG':
11        case 'GIF':
12        case 'XLS':
13        case 'XLSX':
14            flag = true;
15            break;
16        default:
17            flag = false;
18    }
19    return flag;
20}
21function checkFileExtensionLogo(file) {
22    var flag = true;
23    var extension = file.substr((file.lastIndexOf('.') + 1)).toUpperCase();
24
25    switch (extension) {
26        case 'JPG':
27        case 'JPEG':
28        case 'PNG':       
29            flag = true;
30            break;
31        default:
32            flag = false;
33    }
34    return flag;
35}
36function checkFileExtensionVideo(file) {
37    var flag = true;
38    var extension = file.substr((file.lastIndexOf('.') + 1)).toUpperCase();
39
40    switch (extension) {
41        case 'MP4':
42        case 'MOV':
43        case 'WMV':
44        case 'AVI':
45        case 'MKV':
46            flag = true;
47            break;
48        default:
49            flag = false;
50    }
51    return flag;
52}
53//get file path from client system
54function getNameFromPath(strFilepath) {
55
56    var objRE = new RegExp(/([^\/\\]+)$/);
57    var strName = objRE.exec(strFilepath);
58    if (strName == null) {
59        return null;
60    }
61    else {
62        return strName[0];
63    }
64}
65function ajaxFileUploadShopLogo(type, id) {
66   
67    var FileFolder = type;
68    var fileToUpload = getNameFromPath($("#" + id).val());
69    if (fileToUpload != "" && fileToUpload != null) {
70        var filename = fileToUpload.substr(0, (fileToUpload.lastIndexOf('.')));
71        if (checkFileExtensionLogo(fileToUpload)) {
72            var flag = true;
73            if (flag == true) {
74                $("#loading").ajaxStart(function () {
75                    $(this).show();
76                }).ajaxComplete(function () {
77                    $(this).hide();
78                    return false;
79                });
80               
81                $.ajaxFileUpload({
82
83                    url: '../FileUpload.ashx?id=' + FileFolder,
84                    async: true,
85                    secureuri: false,
86                    fileElementId: id,
87                    dataType: 'json',
88                    success: function (data, status) {
89                       
90                        if (typeof (data.error) != 'undefined') {
91                            if (data.error != '') {
92                                alert(data.error);
93                            } else {
94                                id = null;
95                            }
96                        }
97                    },
98                    error: function (data, status, e) {
99                        alert(e);
100                    }
101                });
102            } else {
103                alert('file ' + filename + ' already exist');
104                return false;
105            }
106        } else {
107            id = null;
108            alert('You can upload only jpg,jpeg,png extensions files.');
109            return false;
110        }
111    }
112}
113function ajaxFileUploadProject(type, id) {
114    
115    var FileFolder = type;
116    var fileToUpload = getNameFromPath($("#" + id).val());
117    if (fileToUpload != "" && fileToUpload != null) {
118        var filename = fileToUpload.substr(0, (fileToUpload.lastIndexOf('.')));
119        if (checkFileExtension(fileToUpload)) {
120            var flag = true;
121            if (flag == true) {
122                $("#loading").ajaxStart(function () {
123                    $(this).show();
124                }).ajaxComplete(function () {
125                    $(this).hide();
126                    return false;
127                });
128             
129                $.ajaxFileUpload({
130
131                    url: '../FileUploadM.ashx?id=' + FileFolder,
132                    async: true,
133                    secureuri: false,
134                    fileElementId: id,
135                    dataType: 'json',
136                    success: function (data, status) {
137                    
138                        if (typeof (data.error) != 'undefined') {
139                            if (data.error != '') {
140                                //alert(data.error);
141                            } else {
142                                id = null;
143                            }
144                        }
145                    },
146                    error: function (data, status, e) {
147                        //alert(e);
148                    }
149                });
150            } else {
151                alert('file ' + filename + ' already exist');
152                return false;
153            }
154        } else {
155            id = null;
156            alert('You can upload only jpg,jpeg,png extensions files.');
157            return false;
158        }
159    }
160}
161function ajaxFileUploadJewelry(type,FileName, id) {
162   
163    var FileFolder = type;
164    var fileToUpload = getNameFromPath($("#" + id).val());
165    if (fileToUpload != "" && fileToUpload != null) {
166        var Extension = fileToUpload.substr((fileToUpload.lastIndexOf('.') + 1));
167        var filename = fileToUpload.substr(0, (fileToUpload.lastIndexOf('.')));
168        if (checkFileExtension(fileToUpload)) {
169            var flag = true;
170            if (flag == true) {
171                $("#loading").ajaxStart(function () {
172                    $(this).show();
173                }).ajaxComplete(function () {
174                    $(this).hide();
175                    return false;
176                });
177                $.ajaxFileUpload({
178                    url: '../FileUpload.ashx?id=' + FileFolder + '&Savefile=' + FileName + '.' + Extension,
179                    async: true,
180                    secureuri: false,
181                    fileElementId: id,
182                    dataType: 'json',
183                    success: function (data, status) {
184                       
185                        if (typeof (data.error) != 'undefined') {
186                            if (data.error != '') {
187                                alert(data.error);
188                            } else {
189                                id = null;
190                            }
191                        }
192                    },
193                    error: function (data, status, e) {
194                        alert(e);
195                    }
196                });
197            } else {
198                alert('file ' + filename + ' already exist');
199                return false;
200            }
201        } else {
202            id = null;
203            alert('You can upload only jpg,jpeg,png extensions files.');
204            return false;
205        }
206    }
207}
208function ajaxFileUploadBanner(type, id) {
209    
210    var FileFolder = type;
211    var fileToUpload = getNameFromPath($("#" + id).val());
212    if (fileToUpload != "" && fileToUpload != null) {
213        var filename = fileToUpload.substr(0, (fileToUpload.lastIndexOf('.')));
214        if (checkFileExtension(fileToUpload)) {
215            var flag = true;
216            if (flag == true) {
217                $("#loading").ajaxStart(function () {
218                    $(this).show();
219                }).ajaxComplete(function () {
220                    $(this).hide();
221                    return false;
222                });
223               
224                $.ajaxFileUpload({
225                    url: '../FileUpload.ashx?id=' + FileFolder,
226                    async: true,
227                    secureuri: false,
228                    fileElementId: id,
229                    dataType: 'json',
230                    success: function (data, status) {
231                     
232                        if (typeof (data.error) != 'undefined') {
233                            if (data.error != '') {
234                                alert(data.error);
235                            } else {
236                                id = null;
237                            }
238                        }
239                    },
240                    error: function (data, status, e) {
241                        alert(e);
242                    }
243                });
244            } else {
245                alert('file ' + filename + ' already exist');
246                return false;
247            }
248        } else {
249            id = null;
250            alert('You can upload only jpg,jpeg,png extensions files.');
251            return false;
252        }
253    }
254}
255function ajaxFileUploadMedia(type, id) {
256   
257    var FileFolder = type;
258    var fileToUpload = getNameFromPath($("#" + id).val());
259    if (fileToUpload != "" && fileToUpload != null) {
260        var filename = fileToUpload.substr(0, (fileToUpload.lastIndexOf('.')));
261        if (checkFileExtension(fileToUpload)) {
262            var flag = true;
263            if (flag == true) {
264                $("#loading").ajaxStart(function () {
265                    $(this).show();
266                }).ajaxComplete(function () {
267                    $(this).hide();
268                    return false;
269                });
270                
271                $.ajaxFileUpload({
272                    url: '../FileUpload.ashx?id=' + FileFolder,
273                    async: true,
274                    secureuri: false,
275                    fileElementId: id,
276                    dataType: 'json',
277                    success: function (data, status) {
278                        
279                        if (typeof (data.error) != 'undefined') {
280                            if (data.error != '') {
281                                alert(data.error);
282                            } else {
283                                id = null;
284                            }
285                        }
286                    },
287                    error: function (data, status, e) {
288                        alert(e);
289                    }
290                });
291            } else {
292                alert('file ' + filename + ' already exist');
293                return false;
294            }
295        } else {
296            id = null;
297            alert('You can upload only jpg,jpeg,png extensions files.');
298            return false;
299        }
300    }
301}
302function ajaxFileUploadMediaVideo(type, id) {  
303    var FileFolder = type;
304    var fileToUpload = getNameFromPath($("#" + id).val());
305    if (fileToUpload != "" && fileToUpload != null) {
306        var filename = fileToUpload.substr(0, (fileToUpload.lastIndexOf('.')));
307        if (checkFileExtensionVideo(fileToUpload)) {
308            var flag = true;
309            if (flag == true) {
310                $("#loading").ajaxStart(function () {
311                    $(this).show();
312                }).ajaxComplete(function () {
313                    $(this).hide();
314                    return false;
315                });             
316                $.ajaxFileUpload({
317                    url: '../FileUpload.ashx?id=' + FileFolder,
318                    async: true,
319                    secureuri: false,
320                    fileElementId: id,
321                    dataType: 'json',
322                    success: function (data, status) {
323                      
324                        if (typeof (data.error) != 'undefined') {
325                            if (data.error != '') {
326                                alert(data.error);
327                            } else {
328                                id = null;
329                            }
330                        }
331                    },
332                    error: function (data, status, e) {
333                        alert(e);
334                    }
335                });
336            } else {
337                alert('file ' + filename + ' already exist');
338                return false;
339            }
340        } else {
341            id = null;
342            alert('You can upload only mp4,mov,mkv,wmv,avi extensions files.');
343            return false;
344        }
345    }
346}
347
348function ajaxFileUploadProjectImgs (type, id) {
349    var FileFolder = type;
350    var files = $("#" + id)[0].files; // Get the selected files
351    var validExtensions = ['jpg', 'jpeg', 'png'];
352    var formData = new FormData();
353    for (var i = 0; i < $("#" + id).get(0).files.length; ++i) {     
354        var file = files[i];
355        var fileName = file.name;
356        var fileExtension = fileName.split('.').pop().toLowerCase();
357        if (validExtensions.includes(fileExtension)) {
358            formData.append('userfiles[]', $("#" + id).get(0).files[i]);
359        } else {
360            alert('You can upload only jpg, jpeg, png files. File ' + fileName + ' is not valid.');
361        }
362    }
363    $.ajax({
364        url: '../FileUpload.ashx' + FileFolder,
365        type: 'POST',
366        data: formData,
367        async: true,
368        secureuri: false,
369        fileElementId: id,        
370        dataType: 'json',
371        beforeSend: function () {
372            $("#loading").show();
373        },
374        complete: function () {
375            $("#loading").hide();
376        },
377        success: function (data) {
378            if (data.error) {
379                alert('Error: ' + data.error);
380            } else {
381                alert('File ' + fileName + ' uploaded successfully.');
382            }
383        },
384        error: function (xhr, status, error) {
385            alert('An error occurred: ' + error);
386        }
387    });    
388}
389function ajaxFileUploadProjectImgs(type, id) {
390
391    var FileFolder = type;
392    var fileToUpload = getNameFromPath($("#" + id).val());
393    if (fileToUpload != "" && fileToUpload != null) {
394        var filename = fileToUpload.substr(0, (fileToUpload.lastIndexOf('.')));
395        if (checkFileExtension(fileToUpload)) {
396            var flag = true;
397            if (flag == true) {
398                $("#loading").ajaxStart(function () {
399                    $(this).show();
400                }).ajaxComplete(function () {
401                    $(this).hide();
402                    return false;
403                });
404
405                $.ajaxFileUpload({
406                    url: '../FileUpload.ashx?id=' + FileFolder,
407                    async: true,
408                    secureuri: false,
409                    fileElementId: id,
410                    dataType: 'json',
411                    success: function (data, status) {
412
413                        if (typeof (data.error) != 'undefined') {
414                            if (data.error != '') {
415                                //alert(data.error);
416                            } else {
417                                id = null;
418                            }
419                        }
420                    },
421                    error: function (data, status, e) {
422                        //alert(e);
423                    }
424                });
425            } else {
426                alert('file ' + filename + ' already exist');
427                return false;
428            }
429        } else {
430            id = null;
431            alert('You can upload only jpg,jpeg,png extensions files.');
432            return false;
433        }
434    }
435}
436
437function ajaxFileUploadMulti(type, id) {
438    var FileFolder = type;
439    var filesToUpload = $("#" + id)[0].files; // Access multiple files
440
441    if (filesToUpload.length > 0) {
442        $.each(filesToUpload, function (index, fileToUpload) {
443            var filename = fileToUpload.name.substr(0, fileToUpload.name.lastIndexOf('.'));
444            if (checkFileExtension(fileToUpload.name)) {
445                var flag = true;
446                if (flag == true) {
447                    $("#loading").ajaxStart(function () {
448                        $(this).show();
449                    }).ajaxComplete(function () {
450                        $(this).hide();
451                        return false;
452                    });
453
454                    var formData = new FormData();
455                    formData.append('file', fileToUpload);  // Append each file to FormData
456                    $.ajax({
457                        url: '../FileUploadM.ashx?id=' + FileFolder,
458                        type: 'POST',
459                        data: formData,
460                        processData: false,  // Don't process the files
461                        contentType: false,  // Set content type to false
462                        dataType: 'json',
463                        success: function (data, status) {
464                            if (typeof (data.error) != 'undefined') {
465                                if (data.error != '') {
466                                    //alert(data.error);
467                                } else {
468                                    console.log('File uploaded successfully: ' + fileToUpload.name);
469                                }
470                            }
471                        },
472                        error: function (data, status, e) {
473                            //alert(e);
474                        }
475                    });
476                } else {
477                    alert('file ' + filename + ' already exists');
478                    return false;
479                }
480            } else {
481                alert('You can upload only jpg, jpeg, png extension files.');
482                return false;
483            }
484        });
485    } else {
486        alert('Please select files to upload.');
487    }
488}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.