Solved

Why doesn't this file_get_contents work?

Posted on 2015-02-17
3
74 Views
Last Modified: 2015-02-28
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;
$file_1.="_08_00.xls";
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);
if(!$stage_one)
{
	echo "your alpt.html didn't happen!";
}
else
{
	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?
0
Comment
Question by:brucegust
3 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 450 total points
ID: 40615626
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()
0
 
LVL 31

Assisted Solution

by:Marco Gasi
Marco Gasi earned 50 total points
ID: 40615993
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...
0
 

Author Comment

by:brucegust
ID: 40617403
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?
totals.htm
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question