/    Sign up×
Community /Pin to ProfileBookmark

Warning: file_get_contents($file_not): failed to open stream. how to correct?

in this code below , i am trying to put specific file from directory in an array(right now i have 2 file) and then use one file in function to put the text of file into database table. But file_get_contents is somehow enable to read text file from that array which is formed from directory? please help…
[<?php
$con=mysqli_connect(“localhost”,””,””,”test”);
if (mysqli_connect_errno($con))
{
echo “Failed to connect to MySQL: ” . mysqli_connect_error();
}

function FillinfoTable()
{
$dir = “/Desktopphp_test/”;
$files1 = scandir($dir);
$file=preg_grep(“/additional(w+)/”,$files1);
print_r($file);
$file_not=preg_grep(“/additional(w+)/”,$files1,PREG_GREP_INVERT);
print_r($file_not);

$file_content=file_get_contents(‘$file_not’);
$file_content=explode(PHP_EOL,$file_content);
for($i=0;$i<count($file_content)-1;$i++){
$exploded_content=explode(“: “,$file_content[$i]);
$q=mysqli_query($con,”INSERT INTO ‘g1’ (NAME, DETAIL) values(‘$exploded_content[0]’,’$exploded_content[1]’)”);

}}

FillinfoTable();
mysqli_close($con);
?>]

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmMay 20.2015 — What kind of debugging evidence do you have? What do the two print statements give you? Anything?

You have to do some investigating of your own to solve these kinds of problems. For example, any time you use a function that returns a value, you should CHECK that value to ensure that the function did what you expect. For instance - the scandir line. Did it do what you expect?
Copy linkTweet thisAlerts:
@rootMay 21.2015 — What happens when you try to read the file in a folder on the server and in the servers path, for example most servers folder htdocs.

if it works, that means your server has no permissions to access that file in that manner.
Copy linkTweet thisAlerts:
@NogDogMay 21.2015 — preg_grep() returns an array. file_get_contents() is expecting the pathname to a file, not an array. Once you've dealt with that, I suspect you'll also need to prepend the the directory to the file name.
Copy linkTweet thisAlerts:
@rock24authorMay 21.2015 — could u guys tell me that how can i get absolute path of text files that are inside a directory, so that i can use the path of text files in functions directly?
Copy linkTweet thisAlerts:
@ginerjmMay 21.2015 — Have you done any reading at all on available php functions? The php manual is a wealth of knowledge - all you have to do is read
Copy linkTweet thisAlerts:
@NogDogMay 21.2015 — http://php.net/realpath (for instance)
Copy linkTweet thisAlerts:
@rock24authorMay 22.2015 — thank you sir ?
×

Success!

Help @rock24 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...