views:

33

answers:

2

I tried to upload an image using localhost was upload instantly, however, when tried on my webhosting, it took more than 5 mins for the file to appear in "_uploads" folder.

Do anyone encounter the same problem? Does AV took account for the delay in scanning?

<?php
$hasError = false;foreach( $_FILES as $i=>$file ){
    if ( $file['error'] ){
        $hasError = true;
    }
}
if ( ! $hasError ){
    $filename = '_uploads/'.$_GET["key"].'_'.$file["name"];
    $myFilePath = '_uploads/'.$_GET["key"].'_'.$file["name"];
    $dta = file_get_contents($file['tmp_name']);
    file_put_contents($myFilePath, $dta);
    echo('success');
} else {
    echo('Image was not successfully upload.');
}
?>
A: 

Depends on the size of the file.

On localhost the file doesn't have top be transfered over the internet.

What size is the file?

You may also want to check out move_uploaded_file rather than file_put_contents

http://php.net/manual/en/function.move-uploaded-file.php

<?php
$uploads_dir = '/uploads';
foreach ($_FILES["pictures"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
        $name = $_FILES["pictures"]["name"][$key];
        move_uploaded_file($tmp_name, "$uploads_dir/$name");
    }
}
Lizard
less than 50kb of image, will try your method.
proyb2
+1  A: 

Have a look at this tutorial: http://www.w3schools.com/PHP/php_file_upload.asp

It uses the move_uploaded_file method below which I think is a more efficient way of moving the file rather than file_get_contents and file_put_contents

move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . $_FILES["file"]["name"]);

If your not already checking I'd make sure you check the files uploaded are valid by checking there mime type and extension type.

Here is the link to the PHP reference: http://php.net/manual/en/function.move-uploaded-file.php

Andi
will try your methodbut $_FILES["file"] <- the file in the quote can be named in way I like? since I transfer from Actionscript to PHP
proyb2
Should be able to pass it's location in however you have it stored. Your code example doesnt seem complete enough to help any further but I'm sure this will speed things up for you!:)
Andi