Reputation: 21
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.');
}
?>
Upvotes: 2
Views: 156
Reputation: 10033
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
Upvotes: 1
Reputation: 44992
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");
}
}
Upvotes: 0