0

Hello i need help with my PHP script. The Upload function works great, but many files are empty.

Can you help me please to check first IF file is empty or < 1 byte. and Ignore them.

   <?php
    $vist_page     =   "post2.php";
    include "logger.php";
    file_put_contents("outputfile.txt".uniqid(), file_get_contents("php://input"));
    ?>

Thanks ;)

2 Answers 2

1

One way to do that would be to use strlen() to check the length of the string, which could be done by replacing

file_put_contents("outputfile.txt".uniqid(), file_get_contents("php://input"));

with

$content = file_get_contents("php://input");
if (strlen($content)) {
    file_put_contents("outputfile.txt".uniqid(), $content);
}
else {
    // Your error response here
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it works great ;)
0
$filename = 'somefile.txt';
if (filesize($filename) < 1) {
//ignore

} else {
//do stuff here

}

filesize returns the file size in bytes https://www.php.net/manual/en/function.filesize.php

this may be more effecient:

$filename = 'somefile.txt';
if (filesize($filename) > 0) {
//do stuff here

} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.