• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 83
  • Last Modified:

Why doesn't this file_get_contents work?

Here's my dilemma:

I'm grabbing info from an excel spreadsheet that is a legitimate file, in that I can download and verify that there is data. But when I go to excute "file_get_contents" and then follow it with a "file_put_contents," I get nothing and I'm not even sure how to diagnose things to see where the problem might be.

Here's what I've got:

$file_1="url from where the file is coming from";
$file_1 .=$datestring;
echo $file_1; //I can download the file, so I know I've got data
$datafile1 = file_get_contents($file_1);
$stage_one=file_put_contents('upload/alpt.html', $datafile1);
	echo "your alpt.html didn't happen!";
	echo "something's cookin!";

Open in new window

I've got no idea on how to even start popping the hood on this and figuring out why this doesn't fire.

Any ideas?
2 Solutions
Ray PaseurCommented:
After file_get_contents() use var_dump() to print out the contents of the variable named $datafile1.

And, of course, make sure that the top of your script contains error_reporting(E_ALL).

Let's start with that, then we can look at the return value(s) from file_put_contents()
Marco GasiFreelancerCommented:
I had the same problem trying to access a file in an other domain. The problem was my host had disabled 'allow_url_fopen', so maybe you have the same issue...
brucegustPHP DeveloperAuthor Commented:
Hey, guys!

First off, let me share with you the actual html file that's being uploaded. That way, perhaps, it will be easier for you to diagnose.

It's attached. It's called "totals.html."

Here's what I get with "var_dump:"

string '<div id='comment' style='display:none;'>QUERY_STRING: lteloc=area%25South;emon=05;eday=26;eyr=2014;special_date=ytrdy;trend=07;dw=2;dw=3;dw=4;dw=5;dw=6;lteexhol=1;hr=06;hr=07;hr=08;hr=09;hr=10;hr=11;hr=12;hr=13;hr=14;hr=15;hr=16;hr=17;hr=18;hr=19;hr=20;hr=21;hr=22;username=delvane;rname=volte_7_day;ltereport=totals;gbylte=Region;orderlte=dt;orddir=Asc;submitter=Submit%20Query;ltecontent=volte;maxrows=65535;newwin=on</div>
<div id='tooltip' style='font-size: 8pt;font-family: Tahoma;'>Query Time: 0 sec.</div>'... (length=6400)

BTW: This isn't my code, I'm just trying to take some working code (for the most part), and install it on a different server.

Having said that, I'm getting several warnings. It seems like every value in my html page is not getting recognized.

I get this warning: Trying to get property of non-object in C:\wamp\www\SouthArea\weekly_reports\procedures\procc_volte_7day.php on line 77

I'm getting that for lines 33-77, which is every value, from I can determine. Here's the actual code:

$enddate = $cols->item(0)->nodeValue;
$num_days = $cols->item(1)->nodeValue;
$area = $cols->item(2)->nodeValue;
$mmepool = $cols->item(3)->nodeValue;
$region = $cols->item(4)->nodeValue;
$vendor = $cols->item(5)->nodeValue;
$volte_ia_pcnt = $cols->item(6)->nodeValue;
$volte_lc_pcnt = $cols->item(7)->nodeValue;
$sip_mou = $cols->item(8)->nodeValue;
$volte_qci1_setup_failure_pcnt = $cols->item(9)->nodeValue;
$volte_qci1_setup_failures = $cols->item(10)->nodeValue;
$volte_qci1_setup_attempts = $cols->item(11)->nodeValue;
$qci5_setup_failure_pcnt = $cols->item(12)->nodeValue;
$qci5_setup_failures = $cols->item(13)->nodeValue;
$qci5_setup_attempts = $cols->item(14)->nodeValue;
$seer_pcnt = $cols->item(15)->nodeValue;
$seer_sip_ntwk_eff_calls = $cols->item(16)->nodeValue;
$seer_sip_call_attempts = $cols->item(17)->nodeValue;
$rrc_setup_failure_pcnt = $cols->item(18)->nodeValue;
$rrc_setup_attempts = $cols->item(19)->nodeValue;
$rrc_setup_failures = $cols->item(20)->nodeValue;
$volte_qci1_drop_pcnt = $cols->item(21)->nodeValue;
$volte_qci1_drops = $cols->item(22)->nodeValue;
$volte_qci1_established_calls = $cols->item(23)->nodeValue;
$qci5_bearer_drop_pcnt = $cols->item(24)->nodeValue;
$qci5_bearer_drops = $cols->item(25)->nodeValue;
$qci5_bearer_estab_calls = $cols->item(26)->nodeValue;
$volte_avg_mos = $cols->item(27)->nodeValue;
$volte_mos_numerator = $cols->item(28)->nodeValue;
$volte_mos_denominator = $cols->item(19)->nodeValue;
$volte_pdcp_dl_volume_mb = $cols->item(30)->nodeValue;
$volte_dl_volume_pcnt = $cols->item(31)->nodeValue;
$lte_pdcp_dl_volume_mb = $cols->item(32)->nodeValue;
$x7x24_volte_pdcp_dl_volume_mb = $cols->item(33)->nodeValue;
$x7x24_volte_dl_volume_pcnt = $cols->item(34)->nodeValue;
$x7x24_lte_pdcp_dl_volume_mb = $cols->item(35)->nodeValue;
$volte_pdcp_ul_volume_mb = $cols->item(36)->nodeValue;
$volte_ul_volume_pcnt = $cols->item(37)->nodeValue;
$lte_pdcp_ul_volume_mb = $cols->item(38)->nodeValue;
$x7x24_days = $cols->item(39)->nodeValue;

Open in new window

Finally, the insert statement:

insert into tbl_volte7(enddate,latest_date,area,region,vendor,ran_ia_pcnt,seer_ia_pcnt,volte_lc_pcnt,sip_mou,volte_qci1_setup_failure_pcnt,volte_qci1_setup_failures,volte_qci1_setup_attempts,qci5_setup_failure_pcnt,qci5_setup_failures,qci5_setup_attempts,seer_pcnt,seer_sip_ntwk_eff_calls,seer_sip_call_attempts,rrc_setup_failure_pcnt,rrc_setup_attempts,rrc_setup_failures,volte_qci1_drop_pcnt,volte_qci1_drops,volte_qci1_established_calls) VALUES ('$enddate','$latest_date','$area','$region','$vendor','$ran_ia_pcnt','$seer_ia_pcnt','$volte_lc_pcnt','$sip_mou','$volte_qci1_setup_failure_pcnt','$volte_qci1_setup_failures','$volte_qci1_setup_attempts','$qci5_setup_failure_pcnt','$qci5_setup_failures','$qci5_setup_attempts','$seer_pcnt','$seer_sip_ntwk_eff_calls','$seer_sip_call_attempts','$rrc_setup_failure_pcnt','$rrc_setup_attempts','$rrc_setup_failures','$volte_qci1_drop_pcnt','$volte_qci1_drops','$volte_qci1_established_calls')";

Open in new window

...and I'm getting this error:

Undefined variable: latest_date in C:\wamp\www\SouthArea\weekly_reports\procedures\procc_volte_7day.php on line 92

So, now that I'm seeing the errors, it looks like this thing is broke on several levels. How do I fix it?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now