File size: 12,697 Bytes
433cb52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aebe3c9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ASP to PHP Converter</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://unpkg.com/feather-icons"></script>
    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
    <style>
        .dropzone {
            border: 2px dashed #cbd5e0;
            transition: all 0.3s;
        }
        .dropzone.active {
            border-color: #4f46e5;
            background-color: #eef2ff;
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="max-w-4xl mx-auto py-12 px-4 sm:px-6 lg:px-8">
        <div class="text-center mb-12">
            <div class="flex justify-center mb-4">
                <div class="bg-indigo-100 p-4 rounded-full">
                    <i data-feather="wifi" class="w-12 h-12 text-indigo-600"></i>
                </div>
            </div>
            <h1 class="text-3xl font-extrabold text-gray-900 sm:text-4xl">
                ASP to PHP Converter
            </h1>
            <p class="mt-3 text-xl text-gray-500">
                Upload your ASP files and convert them to PHP for Windows 11
            </p>
        </div>

        <div class="bg-white shadow rounded-lg overflow-hidden">
            <div class="p-6">
                <div id="dropzone" class="dropzone rounded-lg p-12 text-center cursor-pointer">
                    <div class="flex justify-center mb-4">
                        <i data-feather="upload" class="w-10 h-10 text-gray-400"></i>
                    </div>
                    <h3 class="text-lg font-medium text-gray-900">Drag and drop files here</h3>
                    <p class="mt-1 text-sm text-gray-500">or click to browse</p>
                    <input type="file" id="fileInput" class="hidden" multiple accept=".asp,.aspx">
                </div>

                <div class="mt-6">
                    <button id="convertBtn" class="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-medium py-3 px-4 rounded-md shadow-sm flex items-center justify-center transition-colors duration-200">
                        <i data-feather="refresh-cw" class="w-5 h-5 mr-2"></i>
                        Convert Files
                    </button>
                </div>
            </div>

            <div id="fileList" class="border-t border-gray-200 divide-y divide-gray-200">
                <!-- Files will be listed here -->
            </div>
        </div>

        <div class="mt-8 bg-white shadow rounded-lg overflow-hidden">
            <div class="px-6 py-4 border-b border-gray-200">
                <h3 class="text-lg font-medium text-gray-900">Conversion Guide</h3>
            </div>
            <div class="p-6">
                <div class="space-y-4">
                    <div class="flex items-start">
                        <div class="flex-shrink-0 mt-1">
                            <div class="flex items-center justify-center h-6 w-6 rounded-full bg-green-100 text-green-800">
                                <i data-feather="check" class="w-4 h-4"></i>
                            </div>
                        </div>
                        <div class="ml-3">
                            <p class="text-sm text-gray-700">
                                All ASP files will be converted to PHP format compatible with Windows 11
                            </p>
                        </div>
                    </div>
                    <div class="flex items-start">
                        <div class="flex-shrink-0 mt-1">
                            <div class="flex items-center justify-center h-6 w-6 rounded-full bg-green-100 text-green-800">
                                <i data-feather="check" class="w-4 h-4"></i>
                            </div>
                        </div>
                        <div class="ml-3">
                            <p class="text-sm text-gray-700">
                                Supports multiple file upload and batch conversion
                            </p>
                        </div>
                    </div>
                    <div class="flex items-start">
                        <div class="flex-shrink-0 mt-1">
                            <div class="flex items-center justify-center h-6 w-6 rounded-full bg-green-100 text-green-800">
                                <i data-feather="check" class="w-4 h-4"></i>
                            </div>
                        </div>
                        <div class="ml-3">
                            <p class="text-sm text-gray-700">
                                Automatic download of converted files
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        feather.replace();
        
        // Add loader icon to feather
        feather.icons.loader = {
            contents: '<line x1="12" y1="2" x2="12" y2="6"/><line x1="12" y1="18" x2="12" y2="22"/><line x1="4.93" y1="4.93" x2="7.76" y2="7.76"/><line x1="16.24" y1="16.24" x2="19.07" y2="19.07"/><line x1="2" y1="12" x2="6" y2="12"/><line x1="18" y1="12" x2="22" y2="12"/><line x1="4.93" y1="19.07" x2="7.76" y2="16.24"/><line x1="16.24" y1="7.76" x2="19.07" y2="4.93"/>'
        };
const dropzone = document.getElementById('dropzone');
        const fileInput = document.getElementById('fileInput');
        const fileList = document.getElementById('fileList');
        const convertBtn = document.getElementById('convertBtn');
        let files = [];

        // Handle drag and drop
        ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
            dropzone.addEventListener(eventName, preventDefaults, false);
        });

        function preventDefaults(e) {
            e.preventDefault();
            e.stopPropagation();
        }

        ['dragenter', 'dragover'].forEach(eventName => {
            dropzone.addEventListener(eventName, highlight, false);
        });

        ['dragleave', 'drop'].forEach(eventName => {
            dropzone.addEventListener(eventName, unhighlight, false);
        });

        function highlight() {
            dropzone.classList.add('active');
        }

        function unhighlight() {
            dropzone.classList.remove('active');
        }

        dropzone.addEventListener('drop', handleDrop, false);
        dropzone.addEventListener('click', () => fileInput.click());

        fileInput.addEventListener('change', function(e) {
            handleFiles(e.target.files);
        });

        function handleDrop(e) {
            const dt = e.dataTransfer;
            handleFiles(dt.files);
        }

        function handleFiles(newFiles) {
            files = [...files, ...Array.from(newFiles)];
            updateFileList();
        }

        function updateFileList() {
            fileList.innerHTML = '';
            
            if (files.length === 0) {
                const emptyState = document.createElement('div');
                emptyState.className = 'p-4 text-center text-gray-500';
                emptyState.textContent = 'No files selected';
                fileList.appendChild(emptyState);
                return;
            }

            files.forEach((file, index) => {
                const fileItem = document.createElement('div');
                fileItem.className = 'p-4 flex items-center justify-between';
                
                const fileInfo = document.createElement('div');
                fileInfo.className = 'flex items-center';
                
                const icon = document.createElement('div');
                icon.className = 'flex-shrink-0';
                icon.innerHTML = '<i data-feather="file" class="w-5 h-5 text-gray-500"></i>';
                
                const fileName = document.createElement('div');
                fileName.className = 'ml-3';
                fileName.innerHTML = `<p class="text-sm font-medium text-gray-900">${file.name}</p>
                                    <p class="text-xs text-gray-500">${formatFileSize(file.size)}</p>`;
                
                fileInfo.appendChild(icon);
                fileInfo.appendChild(fileName);
                
                const removeBtn = document.createElement('button');
                removeBtn.className = 'ml-4 text-red-500 hover:text-red-700';
                removeBtn.innerHTML = '<i data-feather="trash-2" class="w-5 h-5"></i>';
                removeBtn.onclick = () => {
                    files.splice(index, 1);
                    updateFileList();
                };
                
                fileItem.appendChild(fileInfo);
                fileItem.appendChild(removeBtn);
                fileList.appendChild(fileItem);
            });
            
            feather.replace();
        }

        function formatFileSize(bytes) {
            if (bytes === 0) return '0 Bytes';
            const k = 1024;
            const sizes = ['Bytes', 'KB', 'MB', 'GB'];
            const i = Math.floor(Math.log(bytes) / Math.log(k));
            return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
        }
        convertBtn.addEventListener('click', async function() {
            if (files.length === 0) {
                alert('Please select files to convert');
                return;
            }

            // Show processing indicator
            convertBtn.disabled = true;
            convertBtn.innerHTML = '<i data-feather="loader" class="w-5 h-5 mr-2 animate-spin"></i>Processing...';

            for (const file of files) {
                try {
                    const content = await readFileAsText(file);
                    const phpContent = convertASPtoPHP(content);
                    const phpFileName = file.name.replace(/\.asp$/, '.php').replace(/\.aspx$/, '.php');
                    
                    // Save file locally
                    const blob = new Blob([phpContent], { type: 'text/plain' });
                    const url = URL.createObjectURL(blob);
                    const a = document.createElement('a');
                    a.href = url;
                    a.download = phpFileName;
                    document.body.appendChild(a);
                    a.click();
                    document.body.removeChild(a);
                    URL.revokeObjectURL(url);
                    
                } catch (error) {
                    console.error('Error converting file:', file.name, error);
                    alert(`Error converting ${file.name}: ${error.message}`);
                }
            }
            
            // Reset after conversion
            convertBtn.disabled = false;
            convertBtn.innerHTML = '<i data-feather="refresh-cw" class="w-5 h-5 mr-2"></i>Convert Files';
            files = [];
            updateFileList();
            alert('Conversion complete! Files downloaded.');
        });

        function readFileAsText(file) {
            return new Promise((resolve, reject) => {
                const reader = new FileReader();
                reader.onload = () => resolve(reader.result);
                reader.onerror = () => reject(new Error('Failed to read file'));
                reader.readAsText(file);
            });
        }

        function convertASPtoPHP(content) {
            // Basic ASP to PHP conversions
            let phpContent = content
                .replace(/<%=\s*/g, '<?= ')
                .replace(/<%([^=])/g, '<?php $1')
                .replace(/%>/g, '?>')
                .replace(/Response\.Write/g, 'echo')
                .replace(/Server\.CreateObject\(/g, 'new ')
                .replace(/Set\s+(\w+)\s*=\s*/g, '$1 = ')
                .replace(/\bSub\b/g, 'function')
                .replace(/\bEnd Sub\b/g, '}')
                .replace(/\bFunction\b/g, 'function')
                .replace(/\bEnd Function\b/g, '}')
                .replace(/\bDim\b/g, '</script>
</body>
</html>
)
                .replace(/\bThen\b/g, '')
                .replace(/End If/g, '}')
                .replace(/If\s+(.*?)\s+Then/g, 'if ($1) {')
                .replace(/End While/g, '}')
                .replace(/While\s+(.*?)/g, 'while ($1) {')
                .replace(/Loop/g, '}');
            
            // Add PHP opening tag if not present
            if (!phpContent.includes('<?php')) {
                phpContent = '<?php\n' + phpContent;
            }
            
            return phpContent;
        }
</script>
</body>
</html>