Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi.
I am proceeding with some project. suppose i have a new folder i have many text file inside the folder, i want a php code where it should validate whether the file is empty if the file is not empty if should get stored in database, and if the file is empty it should get stored in some other table in the database. like this it should validate for all the text file. any help will be acceptable.

What I have tried:

PHP
<?php
$uploads_dir = '/uploads';
foreach ($_FILES["pictures"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
        // basename() may prevent filesystem traversal attacks;
        // further validation/sanitation of the filename may be appropriate
        $name = basename($_FILES["pictures"]["name"][$key]);
        move_uploaded_file($tmp_name, "$uploads_dir/$name");
    }
}
?>
Posted
Updated 15-Mar-17 23:39pm
v2
Comments
Member 13062500 16-Mar-17 6:22am    
ya but after validating the file content should get saved in database and the file should move from their

1 solution

Google Search has lots of solutions for checking if: php is file empty - Google Search[^]
 
Share this answer
 
Comments
Member 13062500 16-Mar-17 6:23am    
ya but after validating the file content should get saved in database and the file should move from their
Graeme_Grant 16-Mar-17 6:26am    
There is nothing more to answer. You don't say what DB or supply any sample code where stuck. You don't know how to save data to a DB?
Member 13062500 17-Mar-17 1:19am    
yea i tried now am able to store the content of text file into mysql database bt i want after getting stored the text file should get moved from one folder to another folder
Graeme_Grant 17-Mar-17 2:43am    
Did you try Google Search? 100% of my answers were found that way. Like this: PHP - Move a file into a different folder on the server - Stack Overflow[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900