Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Basic File Get Contents Errors


I'm a newbie and have been learning PHP on and off for a while now.
I am trying to rebuild my website after my host dissapeared along with all my sites data, and I am very nearly 100% complete to the point prior to data loss.

However, one of the pieces of code written by another programmer is simply baffling me at the moment, and I think it may be due to the fact the code was badly written for a much older version of PHP compared to the version the site is on now with my new host etc

The code should be searching for images from one of my suppliers websites but it runs and does nothing at all...I have checked the suppliers URL's and they match the code so what is going on here....am I missing something really simple?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How Do You Make The Contents Of A Text Box Remain, Even After Clicking Send, With Errors ?
How do you make the contents of a text box remain, even after clicking send, with errors?

At the moment, the visitor inputs a load of text into the comments box, but if they click send and there's errors in other fields on the page, the comments box goes blank and they have to start all over again ...

Re Basic File Upload Form
I would like to create a very basic file upload add image form to add
to my web site and to keep them in a "tmp" directory within my web
hosting file manager once uploaded.
I understand the basic html for the form and the basic php scripting
but the fine details ie method post etc needs help also at this stage
I dont want to involve mysql data base. were should I start.

Output Variable Contents In Htm File From Php File
I have a PHP file. No MYSQL database. I'd like to have it open an .htm file and output the results in the php file to the .htm template. So, for example say there is a bunch of variables called:

$make
$model
$year

I want to open a .htm file and output the contents of $make, $model & $year in the htm format using variables in the htm itself. ie. {make} {model} {year} and it would import the contents of each into the corresponding tag.

File Get Contents()
I need to verify, (working on the HTML section of a mailer), If in my php.ini: allow_url_fopen is On Will file_get_contents(file URL) called as follow:

$mailer->Body = str_replace('{MEMBER_NAME}', $member_name, file_get_content($htmlBody) );

Allows the file to become my email body? where $htmlBody comes from the DB...

Getting The Contents Of A File.
Is it possible to get the contents of a file; display the contents in a textbox; and edit the contents of that file. Then click a button and change the contents to the new updated file.

The reason I want to know this is because I have programmers on my site and I don't want them to have access to the FTP or cPanel. They will jus enter the name of the file, click submit, be able to edt and replace that file. All without FTP or cPanel.

File Put Contents
looking to write to a file with out overwriting the previous data?  is there a way to turn overwrite off with the file put contents?? im trying to keep a log of form data.

File Get Contents
i am trying the example of get_file_contents but i get the following error.

what i want to do is get all the web page of google but the code wont work any ideas please cheers.

Warning: file_get_contents() expects at most 2 parameters, 5 given in

<?php
$content=file_get_contents("http://www.google.com",FALSE,NULL,0,20);
echo $content;
?>

Deleting Contents In File With PHP
Hi, I need to get to a specific part of the file and delete a line so i can overwrite it with a new value. Example ...

$Money = array(
0 => 10000,
1 => 932394,
2 => 3254#<Money>
);

I need to change first choice "0 => 10000" and replace it with "0 => 7500" so it seems like they spent 2500 moneys I dunno if its possible but if it is please help, and thanks in advance FYI, the file is called testfile.inc and i dunno what that .inc means :P I just got it from a script i downloaded Further more, i want to do this change/replace through a form or a click using PHP.

File Get Contents Issue.
In folder WWW i have text file named news.txt. I'm calling file_get_contents("news.txt"); form index.php in the same folder. I got error:

Warning: file_get_contents(news.txt): failed to open stream: No such file or directory in /home/www/index.php on line 14.

File Get Contents - Timeout
I Have googled and founds lots of references and examples of stream_set_timeout for fsockopen, but none showing how you apply a timeout to file_get_contents which I need to use in this case.

Can anyone give me a sample of how to set a timeout on file_get_contents, as I understand that it can be applied to all PHP streams?

This does not timeout after 2 seconds:

$url ="http://www.mydomain.com";
stream_set_timeout($contents, 2);
$contents = file_get_contents($url, false);
Print $contents;

File Get Contents() Error
I made a PHP5 script that uses the file_get_contents() funtion and when I run the script, I get this error:

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration

I called my host up and they said that it is a coding error, not a security or server error,

Here is the code:

<?php
$address = "http://www.example.com";
echo htmlspecialchars(file_get_contents($address));
?>

Put Contents Of XML File Into An Array
I need some way to generate an array that holds the same structure and data of a xml file.

File Get Contents .limitation?
See this simple file_get_contents code

<?php
$link= 'http://www.example.com'
$content=file_get_contents($link);
echo $content;
?>

I tried the code with these links:

1. http://www.example.com (...worked OK. Also tried google.com, yahoo.com,... all OK.)

2. http://www.example.com/buy/chess (...$content captured an error page instead of the result)

3. http://www.example.com/chessmotifs (...$content returned nil, ... totally nothing. This is the one I need the code to work btw.)

Could this be because the site (in this case cafepress) uses some sort of scripts to generate their sub-pages? If yes, is there an alternatif method to "file_get_contents" that allows a page to generate fully before capturing?

Reading File Contents
I am parsing a file delimited by |. For some
reason the content is displayed to the browser properly - but the loop
is consistenlty outputting "one more row" of just the titles.
Perhaps I'm going about it completely wrong:

<?php

$filename = 'books.file'
$fp = fopen("$filename", "r");

while (!feof ($fp)) {
$contents[] = explode("|", fgets($fp, 4096));
}
fclose ($fp);
$loop=1;
foreach ($contents as $row) {
echo "<b>$loop</b> -------------------<br>";
echo "<b>Reviewer</b>: $row[0]<br>";
echo "<b>Date</b>: $row[1]<br>";
echo "<b>Title:</b> $row[2]<br>";
echo "<b>Author:</b> $row[3]<br>";
echo "<b>Rating:</b> $row[4]<br>";
echo "<b>Comments:</b> $row[5]<br><br>";
$loop++;
}

echo "<a href="bookreview.html">Insert a new book review</a>";

?>

If File Contents Equals
I'm trying to create a script that will check the contents of the file and will display a certain message if it does equal the correct value. How would I go about checking a files contents? I tried

if (readfile("$file1") == "144.173.19.121") {
echo "your ip";
} else {
echo "doesn't work";}

File Contents To Variables
I have a file populated with information formated as on many lines:

date: person:id:info:info2

please note that : is the seperater. How can I get this data into variables:

$date:$person:$id:$info:$info2

I can open the file, display it's contents, even take the : out of it with this code I got from php.net: PHP Code:

Reading Zip File Contents
say i have a zip file - test.zip - with a file - somefile.txt - in it,
whose contents are as follows:

this is a test

when i try running the following script on the above zip file, i get
everything i should be getting, save for the contents of somefile.txt
(example output follows the script):

<?
$filename = 'test.zip'
if (($temp = zip_open($filename))) {
while ($entry = zip_read($temp))
if (preg_match('/.txt$/',zip_entry_name($entry))) {
print "file name = '".zip_entry_name($entry)."'
";
print "file size = '".zip_entry_filesize($entry)."'
";
print "contents = '".zip_entry_read($entry)."'
";
}
zip_close($temp);
}

?>

the output is as follows:

file name = 'somefile.txt'
file size = &#3914;'
contents = ''

the output i would like and expect is as follows:

file name = 'somefile.txt'
file size = &#3914;'
contents = 'this is a test'

Need To Read The File Contents
I have a small problem.i need to read the file contents from the url.here is the desc of the problemthe file(local file with compelte path) name should pass thru url(no file upload option)so i need to read that file and store that content in the databasehere is the examplehttp://example.com/read.php?file="D://text.txt"Once i enter this url in the browser, i need to read that text.txt file and store the content of text.txt into DB.

Open File And Get Contents
I need to open a file and then echo the contents into a text area. I tried file_get_contents(), but it doesn't work, it isn't recognised as a function..

Any other way of doing this?

Delete File Contents
Can someone post some code to show me how to delete a file from a folder please? I need to delete a file first, and then upload something in it's place. Maybe a bit of code to slide in what i have already would work? Code:

How To Append A Flv File Contents To Another Flv File.
Could u pls helpe me how to append a flv movie file to another flv movie file.

Csv File Gives Errors In Excel?
Ive created a script that generates a csv file on the webserver, whereafter the user can download it, in order to open it in Excel. Excel gives the following error:

1) cannot read record 1
2) File myfile.csv is not a valid SYLK format.

I really don't know whats wrong. The first 3 rows look like this of the csv file look like this:

ID;Relationname;City;Article;Period;Startdate;Amount;Price;Total;Interval
1300;Restaurant BeauBeaty;London;LTP1;quater;01-08-1999;1;12.50;300.00;200308-200507
1303;Café Blue moon;Leeds;LTP1;year;01-08-1999;1;0.00;358.80;200308-200507

Anyone a clue why Excel doesnt want to read this? (It won't even read the 3 lines only, after deleting the other rows)

How Do I Open A Dir And Print The Contents Of Each File?
i can do it in perl with this

$dirtoopen = "./database/";
opendir(DIR, "$filetoopen") or die "cannot open";
@files = readdir(DIR);
closedir(DIR);

foreach $file(@files){
$filetoopen = "./database/$file";
open(FILE, "$filetoopen") or die "cannot open";
$contents = <FILE>;
close(FILE);
($addonname, $description, $submitter) = split(//, $contents);
print "$addonname | $description";
}

but how would i with php?

Overwrite File To Update Contents
I'm hoping someone can help me figure this little problem i am having with the following PHP script... i have registration form that a person can use to sign up for email, and when they submit there information, i have a script that is suppose to write to a text file the username and email address...
however, is there a way to delete the contents of the text file or overwrite it completely with all the usernames and email addresses in the database(which was already there to begin with) plus the new person's username and email address???? the idea here is to have the most current info from the database be written to the text file when someone signs up for email...
the following code snippet is the code that is suppose to place the new user's username and email address...

Displaying Contents Of A Text File?
I'm trying grab the content of a text file and print it a web page. I believe that I should be using something along the lines of "file" or "fopen", but I'm not having any luck. Any thoughts or tips?

Printing The Contents Of Each File In A Directory
I've been trying to create a PHP page that reads each file in a directory (txt, for example), and then outputs the contents of the file. The purpose for this is for someone advertising products for a website, so that he can use a form to describe the product, and then saves each entry as a new txt file.

I then want the php to print the contents of the file. I've set it up so that it is html code, so formatting is not an issue.

I've figured out how to read the contents of a single file, using file_get_contents. I can also display each file NAME from the directory. However, when I add file_get_contents into the loop, the php script wont run.

Here's what I have so far:

<?php

     $handle = opendir('sales');

if($handle)
{
   while(false !== ($file = readdir($handle)))
   {
print "$file <br>";

$contents = file_get_contents($file);
print "$contents <br>";
   }
closedir($handle);
}?>

I've tried using seperate php entries and also had a play with readf and such, but can't seem to get anything to work. It seems like a common thing to want to do, and I've probably just made a small mistake somewhere?

File Upload -- Completed But With Errors
This is the working, completed PHP script for file upload. The only problem is: wenn i send file and when the file is upload on the server, the file name ( orginal file name is bla.gif ) is converted to something like this img34b123.gif.

The file is stored in wright directory and there is no problems with upload.
Could this be programming error or is this error/problem of the linux admin.

I have asked linux admin if there is a temp directory where the temp files
are stored, before there are uploaded, but he says no. So i cant find the
problem here...

<?php if ($HTTP_POST_VARS['action']) { ?>
?>
</BODY>
</HTML>
<?php } else { ?>
<HTML>
<HEAD>
</HEAD>

<BODY BGCOLOR="WHITE" TEXT="BLACK">
<P><FONT FACE="Arial, Helvetica, sans-serif">

<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="<?php echo
$PHP_SELF;?>" name="bla">

<INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="60000">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="1">

File for upload:
<INPUT TYPE="FILE" NAME="file1" SIZE="30">
<INPUT TYPE="SUBMIT" VALUE="Send">

</FORM>

</FONT></P>
</BODY>
</HTML>
<?php } ?>

<?php if ($HTTP_POST_VARS['action']) { ?>
<HTML>
<HEAD>

</HEAD>
<BODY BGCOLOR="WHITE" TEXT="BLACK">
<P><FONT FACE="Arial, Helvetica, sans-serif">
<?php

$uploadpath = '/testDir/Photos/'
$source = $HTTP_POST_FILES['file1']['tmp_name'];
$dest = ''

if ( ($source != 'none') && ($source != '' )) {

$imagesize = getimagesize($source);

switch ( $imagesize[2] ) {

case 0:

echo '<BR> Wrong Photo <BR>'
break;

How Do You Suppress Errors Produced By File()
I'm getting this error:

<b>Warning</b>:
file(http%3A%2F%2Fwww.publicpen.com%2Fupdate.php%3 FcbHeadline%3DTestimonials%26amp%3BcbDateCreated%3 D%26amp%3BcbUserName%3D%26amp%3BpageAddress%3Dhttp %3A%2F%2Fwww.publicdomainsoftware.org%2Fgo%2Findex .php%3FpageId%3D33119):
failed to open stream: No such file or directory in
<b>/home/httpd/vhosts/publicdomainsoftware.org/httpdocs/go/pdsIncludes/CommandUpdatePublicPen.php</b>
on line <b>64</b><br />

these are lines 56-64:

$url = "http://www.publicpen.com/update.php";
$url .= "?cbHeadline=$cbHeadline";
if ($cbHeadline == "") $url .=
"&amp;cbMainContent=$cbMainContent";
$url .= "&amp;cbDateCreated=$cbDateCreated";
$url .= "&amp;cbUserName=$cbUserName";
$url .= "&amp;pageAddress=$pageAddress";

$url = urlencode($url);
$arrayOfPublicPenResponse = file($url);

Place File Contents Into Table On Page
Hi all. Am new to PHP and trying to get the following to work. I dont know if it is possible at all, and would appreciate any help.

I have a folder called Books. It contains an htm page called books.htm which has some graphic elements on it. It also contains a file (either excel or csv, or tab delimited.... whichever will work best in this situation). This file contains two columns. 1st colums-1st row contains an image name (e.g. alice.gif). And the 2nd column-1st row contains a text discripition (e.g. Alice in Wonderland....bla bla..). And so on for the next rows. The folder also contains the actual 'alice.gif' and all images that are listed in the 1st column.

What i am trying to achive is thus:-
When the books.htm page is called. I want the table in the file to be recreated on the page under the existing graphic elements. In that table, instead of the image names in the first column, i want the actual image (which is present in that folder), to be planted there in that specific cell on the htm page!

Read A Text File Where Contents Are Going Over 2 Lines
I have this code to read the contents of a text file: PHP Code:

Read The Contents Of A Text File Into MySql Using PHP
New to this, have the basics, can build a form and such. My problem is I
need to be able to open a file on a pc/s on the network, read the data
character by character, check to see if a certain character is present, if
it is, update the database and continue reading the file until it comes
across the character again, updates the database and so on . . . .

Supress Errors At The Page Level? Undefined Index Errors.
I'm creating a simple reply form, and if a form item isn't answered I
get an error:
"Notice: Undefined index: rb_amntspent in
c:inetpubwwwrootmackinawsurvey.php on line 36"
even if in the code I allow for an unselected item. (Code at the
bottom here.)
It works fine otherwise.

Now in the past I've made a change to php.ini to repress errors, but
for this project I don't have access to the php.ini.
Is there a way to supress errors on that page for that session?

Or, is there a way to just not get that error at all?

Here's a sample of the code that gets the form response. If an item is
selected, no error for that question, but if an item is not selected I
get the error above even though I still get a successful echo for the
"else" or "default" option which occurs if nothing is selected:

$rb_visited = $_POST["rb_visited"]; //Have you ever visited Mackinaw
City, Michigan?
if ($rb_visited == "1") {
$rb_visited_reply = "Yes";
} elseif ($rb_visited == "0") {
$rb_visited_reply = "No";
} else {
$rb_visited_reply = "You did not answer this question";
};

$rb_lastvisit = $_POST["rb_lastvisit"]; //When was your last visit to
Mackinaw ity?
switch ($rb_lastvisit) {
case "1":
$rb_lastvisit_reply = "Earlier this year (2003)";
break;
case "2":
$rb_lastvisit_reply = "Last year (2002)";
break;
case "3":
$rb_lastvisit_reply = "2 years ago (2001)";
break;
case "4":
$rb_lastvisit_reply = "3 years ago (2000)";
break;
case "5":
$rb_lastvisit_reply = "4 or more years ago (1999)";
break;
default:
$rb_lastvisit_reply = "You did not answer this uestion";
}

File Get Contents Does Not Work When Reading Pages From 'mydomain.com'
Working on Linux, I created this script:
---
$url = "http://www.mydomain.com";
$html = @file_get_contents($url, "r") or die("Can't open URL");
echo $html;
-----

This script:
- works ok on my PC box (PHP 4.4.5) with 'http://www.google.com'
- works ok on my PC box (PHP 4.4.5) with 'http://www.mydomain.com'
- works ok on my server (PHP 4.4.2) with 'http://www.google.com'
- DOES NOT work on my server (PHP 4.4.2) with 'http://www.mydomain.com'

Does anybody have any tip to find out why I can't read 'http://www.mydomain.com' on my server? Must I modify something on my 'mydomain.com' server (I manage it)?

Catching "File Name Too Long" Errors
Is there a way to redirect on "file name too long" errors?

I'm using mod_rewrite to handle all unknown urls with an error page.
That's not working for this error. Apparently the "file name too long"
error occurs before mod_rewrite is invoked.

Setting up an ErrorDocument is also ignored, even though it looks to the
user (and listed in access.log) as a 403 error, it's not a normal 403
error.

Basic IF
I use the following code:

ftp_chdir($conn_id, $destination)

I want to use an IF statement that says if the ftp_chdir command is not successful, then run some commands, else (therefore if it works), run some different commands.

But i seriously am stuck as to how to write the statement.

Basic PHP Question
My previous question has fetched no results, so let me try rephrasing the question. What I am able to do with PHP is open a new window with javascript, returning a MySQL query. What I want to be able to do is somehow, with a click event, have an embeded PHP script update, showing the same results as the new window.

Basic Question About PHP
I am using Solaris 2.7 and I would like to install PHP on my server. However, I am not running Apache right now, instead it is running NCSA. I have installed mysql as well and would like to use the persistent database connectivity. Do I need to be the administrator to install PHP?

Another question: Can PHP work with CGI? For example, if an HTML form is submitted to the backend via cgi post method, can the same data (in the same form) be send to databases (e.g. mysql) via PHP?

Basic If/Then Statement
I have a script that generates a random image based on the random line it pulls from a .txt file. So in the file there exists this:

image/banner1.gif
image/banner2.gif
image/banner3.gif

PHP Code:

Basic Shell_exec
I am trying to use shell_exec to do some scheduled clearing up but can't get it working.
PHP Code:

Doing Basic Authentication On IIS 6.0
I'm trying to do basic authentication using IIS 6.0 with PHP as an ISAPI module. I can get the dialog to pop up no problem, but when I enter a name/password, it doesn't come back in the header. After checking the documentation, I found that the $PHP_AUTH_USER and $PHP_AUTH_PW are not available in IIS 6.0 and that I had to use the HTTP_AUTHORIZATION variable like so:

list($user, $pw) = explode(':',
base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));

..........

Very Basic PHP Tutorial Available?
I am not a programmer, and I want to do a 301 redirect for my site and do not have access to htaccess.

But I do have access to PHP apparently with certain site packages (and found the code to use online). I signed up and got lots of great new files and have no clue what to do with them.

So, is there a really basic step-by-step tutorial for what to do with PHP? I just want to forward my html pages, and need a really basic instruction source that probably starts something like: make a new file and name it X.

PHP On IIS With Basic Authentication
I'm running PHP on IIS and need to set basic authentication on a
particular folder, e.g http://domain.com/private/
I've set the user on the server and assigned permissions to the
folder.

When requesting files within the folder, I get the login/password
prompt and entering the correct credentials gives me the file, except
for .php files.

The .php file is as basic as they come with just <?php echo "Hello
world"; ?as the contents.

http://domain.com/private/test.txt works perfectly, however
http://domain.com/private/test.php denies access, giving only:
"Unauthorized
Access is denied due to invalid credentials."

I've tried giving the user full permissions; I've ensured that
Application Settings configuration within IIS Manager properties >
Home Directory, allows PHP files.

Basic Math
<?php
$variable = "random number here";
$percentage = $variable - 10%;
// $percentage allways will contain 90% of whatever the monetary value was in variable
?>
Is the above correct, and 100% accurate?

Need Help With Basic Php Mysql Query
$z = "goodBMW"; the word goodBMW is no where to be found in in the table times. but it will echo every single row thats in that table and it doesend sort between Group 1 and Group 2 where the hell is my query wrong.

Making A Basic Search
Here's the query to start with..

Basic XML_parse Question
I've been given a PHP script which results in the following string:

<authentication success="true" cn="lupoli" firstname="Jeremy" lastname="Lupoli" />

I've been using explode to grab the appropriate data here, but it was suggested to me that an XML parser was the more appropriate way to go. I'm guessing XML_parse will do the trick.

Basic Security Check
I'm looking for some simple code to ensure that a $variable read from the URL originates on my site.

Example URL:

http://mysite.com/page.php?variable=1

I want code that prevents someone from calling a file from another site, for example:

http://mysite.com/page.php?variable=http://badsite.com/file.exe

Basic Regular Expression
I need to check a string to make sure it only has letters, and/or numbers and/or an underscore in it.

Control Structure (Basic)
I'm basically creating a chart system, where new entries into the chart are highlighted via a change in the background colour of their HTML table row.

The problem I have is that the following code generates a "Parse Error", please can someone tell me where I'm going wrong?

---------------------------------
$tablecolor = "000000"

if ($lastweek = "NE")
let $tablecolor = "0000ff";
---------------------------------

The error comes in the "if....." statement line.


Copyright © 2005-08 www.BigResource.com, All rights reserved