Results 1 to 4 of 4

Thread: Convert php script to Javascript

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Wink Convert php script to Javascript

    Hi friends,

    I am familiar in Asp.net. I have a php script code for flash uploading. I need to convert this php script to java script. For ur's reference i put the code below,

    <?php
    include("JSON.php");
    $result = array();

    if (isset($_FILES['photoupload']) )
    {
    $file = $_FILES['photoupload']['tmp_name'];
    $error = false;
    $size = false;

    if (!is_uploaded_file($file) || ($_FILES['photoupload']['size'] > 2 * 1024 * 1024) )
    {
    $error = 'Please upload only files smaller than 2Mb!';
    }
    elseif (!$error && !($size = @getimagesize($file) ) )
    {
    $error = 'Please upload only images, no other files are supported.';
    }
    elseif (!$error && !in_array($size[2], array(1, 2, 3, 7, 8) ) )
    {
    $error = 'Please upload only images of type JPEG.';
    }
    elseif (!$error && ($size[0] < 25) || ($size[1] < 25))
    {
    $error = 'Please upload an image bigger than 25px.';
    }
    else {
    move_uploaded_file($_FILES['photoupload']['tmp_name'], "./uploadedfiles/".$_FILES['photoupload']['name']);
    chmod("./uploadedfiles/".$_FILES['photoupload']['name'], 0777);
    }

    $addr = gethostbyaddr($_SERVER['REMOTE_ADDR']);

    $log = fopen('script.log', 'a');
    fputs($log, ($error ? 'FAILED' : 'SUCCESS') . ' - ' . preg_replace('/^[^.]+/', '***', $addr) . ": {$_FILES['photoupload']['name']} - {$_FILES['photoupload']['size']} byte\n" );
    fclose($log);

    if ($error)
    {
    $result['result'] = 'failed';
    $result['error'] = $error;
    }
    else
    {
    $result['result'] = 'success';
    $result['size'] = "Uploaded an image ({$size['mime']}) with {$size[0]}px/{$size[1]}px.";
    }

    }
    else
    {
    $result['result'] = 'error';
    $result['error'] = 'Missing file or internal error!';
    }

    if (!headers_sent() )
    {
    header('Content-type: application/json');
    }

    echo json_encode($result);

    ?>

    In the above code a temporary file created and the uploaded files are stored in that folder.I need to convert this code in javascript.

    I hope ur's reply

    Thanks
    Failing to plan is Planning to fail

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Convert php script to Javascript

    You can't save files on the server using Javascript as it is a client side language. Therefore it cannot be converted.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up Re: Convert php script to Javascript

    k how convert to .aspx.vb this php file
    Failing to plan is Planning to fail

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Convert php script to Javascript

    The page below shows how to upload a file using ASP.NET:

    http://support.microsoft.com/kb/323245
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width