Solved

Convert PHP to ASP

Posted on 2006-11-29
9
368 Views
Last Modified: 2010-04-06
This is probably a big ask but can anyone convert this PHP to ASP.  We only support ASP at the moment but this is a great HTTP Upload tool

Many thanks if it can be done.

Julie


<?php
    /* check for and loop through uploaded files */
    foreach ($_FILES as $name => $info) {
        /* chekc the file has a valid name */
        if (($info['name'] != 'ht.access' && 
            substr($info['name'], 0,1) != '.' && 
            $info['name'] != 'allowed_files')) {

            /* attempt to move the file to the uploaded_files directory */
            if (@move_uploaded_file($info['tmp_name'], "uploaded_files/files/{$info['name']}")) {
                /* get the contenst of the array of files */
                $file_arrays = @unserialize(@file_get_contents('uploaded_files/allowed_files'));        
     
                /* if there are more already 5 files, remove the oldest item fomr the array
                 * and delete it  
                 */
                if (count(@$file_arrays['files']) == 5) {
                    $name = array_shift($file_arrays['files']);
             
                    unset($file_arrays['types'][$name]);
                    @unlink('uploaded_files/files/' . $name);
                }

                /* add the new item to the arrays */
                $file_arrays['files'][] = $info['name'];
                $file_arrays['types'][$info['name']] = $info['type'];

                /* serialize the array and write it back to the file */
                if ($fhwnd = @fopen('uploaded_files/allowed_files', 'wb+')) {
                    fwrite($fhwnd, serialize($file_arrays));
                    fclose($fhwnd);
                }
            }          
        }    
    }
?>
<html>
    <head>
        <title>Form Post Dump</title>
    </head>
    <body>
        <?php if ($_POST): ?>
            <p>You submitted the following POST variables with the following names:</p>
            <ul><?php foreach($_POST as $name => $var) : ?>
                <li><?php echo(htmlspecialchars($name)) ?> = <?php echo(htmlspecialchars($var)) ?></li>
            <?php endforeach; ?></ul>
        <?php endif; ?>
        <?php if ($_GET): ?>
            <p>You submitted the following fariables with the query string:</p>
            <ul><?php foreach($_GET as $name => $var) : ?>
                <li><?php echo(htmlspecialchars($name)) ?> = <?php echo(htmlspecialchars($var)) ?></li>
            <?php endforeach; ?></ul>
        <?php endif; ?>
        <?php if ($_FILES): ?>
            <p>You submitted the following FILES:</p>
            <ul><?php foreach($_FILES as $name => $info): ?>
                <li>File name: <?php echo(htmlspecialchars($name)) ?>
            <ul>
                <li>Client file name: <?php echo(htmlspecialchars($info['name'])) ?></li>
                <li>File MIME type: <?php echo(htmlspecialchars($info['type'])) ?></li>
                <li>File size: <?php echo(htmlspecialchars($info['size'])) ?></li>
                <li>Download link: <a href="uploaded_files.php?file=<?php echo(htmlspecialchars($info['name'])) ?>"><?php echo(htmlspecialchars($info['name'])) ?></a></li>
            </ul>
            </li>
        </ul>
            <?php endforeach; ?></ul>
        <?php endif; ?>
        <form enctype="multipart/form-data" action="<?php echo($_SERVER['PHP_SELF']) ?>" method="post">
            <p>Variable1: <input type="text" name="variable1" /></p>
            <p>Variable2: <input type="text" name="variable2" /></p>
            <p>Variable3: <input type="text" name="variable3" /></p>
            <p>File: <input type="file" name="file1" /></p>
            <p><input type="submit" value="Post" /></p>
        </form>
    </body>
</html>
<?php
// vim: expandtab nowrap softtabstop=4 tabstop=4 shiftwidth=4
?>
0
Comment
Question by:jcwiatr
  • 4
  • 3
9 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 500 total points
ID: 18061257
jcwiatr,

You are better off not trying to convert this script.  The main reason is you can't really convert it.  In the case of uploading files ASP does not handle things like PHP, in fact ASP doesn't really provide an upload file function/component like PHP does.  I personally recommend and use ASPUpload which is a very popular third party component you can install on you ASP server.  There is some information on it and other option for ASP in http:Q_22065191.html.  We can certainly help you implement one of these on your site but I wouldn't try to start from the PHP script above.  The html from that page is the only thing that would "convert" easily.

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 16

Expert Comment

by:ThinkPaper
ID: 18148121
look into the pure asp upload provided on that question b0lsc0tt provided - very easy to set up and use. =)
0
 
LVL 1

Author Comment

by:jcwiatr
ID: 18290497
hi b0lsc0tt, abundance of info. thanks.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 18294093
Your welcome.  I'm glad that I could help.  However is the C grade an accident or did you still need some help?  From your last comment it would seem to be an accident.  If you still have questions or need help then just let me know.  It is nice to have the chance to earn the A.

bol
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:jcwiatr
ID: 18298067
you are quite correct.  it was an accident indeed. EE is not very forgiving once a response is commited.  Do you know how I can change it ?
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 18298135
LOL.  They forgive.  I'm glad to know that it was not intentional and you still needed help.  Post a message in Community Support (http://www.experts-exchange.com/Community_Support/).  No points are needed.  Ask for them to reopen the question so you can change the grade and copy this question's URL into the body.  A moderator will respond and reopen the question.  Let me know if you have a problem or any questions about doing this.

bol
0
 
LVL 1

Author Comment

by:jcwiatr
ID: 18299226
ta.  will do.  I cannot currently create a ticket with no points so once this is resolved I will go through the process.  Thank-you.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 18305576
Your welcome!  Thanks for the extra work to get the grade corrected.  It was a fun question and I'm glad I could help.  PashaMod, thanks for the help!

bol
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to i line up css containers from left to right 35 23
TripAdvisor Widgets on WordPress Websites 10 108
Using YubiKey with REST API application 2 108
Cordova Camera plugin fails 2 98
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now