Solved

Why doesn't this file_get_contents work?

Posted on 2015-02-17
3
77 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 110

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

732 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