Solved

Why doesn't this file_get_contents work?

Posted on 2015-02-17
3
73 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

821 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