Results 1 to 2 of 2

Thread: Convert php script to Javascript

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up 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
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Convert php script to Javascript

    You mean you need to convert it to ASP.NET? Because you can't really do a file upload with a client side scripting language like JavaScript.

    Read this article on how to upload files in ASP.NET
    http://www.4guysfromrolla.com/webtech/091201-1.shtml

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