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




Getting Contents Of Folder


I've made half of the code for a little "hosting" site for a few of the members of my site. Their files are uploaded to /login/<username>/

I'm now stuck as to how to show the contents of the folder in a page. I think the use of fopen() is needed, however the php website is a little confusing.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Getting And Using Contents In A Folder
I want to make a photogallery/slideshow with PHP...

The 'gallery/slideshow' would show up inside a new window.
basically, I just want links with possibility to go:

- forward
- back
- to the very beginning
- to the very end
- away (close the window)

Can I use PHP to determine the contents of the folder with the pictures and then use variables to determine which photo to show, and what URL's should be generates for the arrows? So each folder with a series of photographs would have one PHP file and the pictures themselves in them (it's not a problem to rename them).

Should be simple enough, but I'm just starting out with PHP, and I'd like to have something working as soon as possible... the website I'm working on is about to launch soon (my first 'commercial' web project :) ), and this is about the only thing left that I still have to sort out how to do...

Delete Folder And Its Contents
is there any way of deleteing a folder and all of its contents using PHP?

Deleting Folder And Contents With PHP
Im using this code to delete a folder using my script but it says Directory not empty. What code could i use that will delete the folder, subfolders, and all its contents.

$currentdir = getcwd();
$directory="$currentdir/users/$_COOKIE[username]/albums/$_GET[albumname]";
rmdir($directory);

Folder Contents Function?
I'm looking for a function that puts the contents of a folder (the file names) into an array. Is there such a beast? For instance, if there is a folder off of my root called /tips/, and I want to list the files that are in it, such as tip1.txt, tip2.txt, etc.

Copy Entire Contents Of A Folder To Another
Situation:

I am creating a folder based on input from a form and then creating an images folder underneath that -- that works great and I can read and write to the newly created folders AS LONG AS IT IS ONE FILE AT A TIME!!!

What I would like to do:

I would like to copy the contents of an entire folder over to one of the newly created folders ALL AT ONCE -- or in a loop -- which is what I am trying to do but keep getting denied.

My code as it is now:
if ($handle = opendir("$sourcedir")) {
echo "Directory handle: $handle<br><br>";
echo "Files:<br><br>";
while (false !== ($files = readdir($handle))) {
if ($files != "." && $files != "..") {
if (!copy($files, $imagepath)) {
echo "failed to copy $files into $imagepath<br><br>";
}
}
}
closedir($handle);
}

all of the variables are working fine... it goes through the loop just fine -- I know this because it prints out the error for every file in the folder... it just won't copy the files over to the new folder while in this loop.

Here is the beginning of the error messages:
Directory handle: Resource id #2
Files:
failed to copy step_c1.gif into /htdocs/www/schemes/adfasa/images
failed to copy step_b1.gif into /htdocs/www/schemes/adfasa/images
failed to copy step_a1.gif into /htdocs/www/schemes/adfasa/images

by the way: adfasa is the folder name brought in by the form and images is the folder I create underneath it.

Is this something that is possible to do in a loop? If so, what is wrong with this one. If not, how is something like this done?

Of course since I know the files that are in the folder I want to copy from I could just go ahead and copy them ONE by ONE but that doesn't seem to be very efficient.

Syncronizer - Synchornize Folder Contents
is there anyway to sync to folders Contents between two Computers in PHP...

List Contents Of A Folder, Make List Of Links
Does anyone know how I can write a script that:

- reads in all the files in a particular directory
- displays the file names in a html list and makes a link of them:
<ul>
<li><a href="filelocation1">filename 1</li>
<li><a href="filelocation2">filename 1</li>
<li><a href="filelocation3">filename 1</li>
</ul>

etc.?

So basically it creates a list of links with the contents in that directory,
so you can download them from there.

Drag Files From One Folder To Another Folder (copy) .. Possible?
Is it possible to write codings PHP or Javascript.. GUI representation
of File handling (ie. Drag files from one folder to another folder (copy)
like our windows).. pls give me some reference codings like this..

Remove From $name (folder)/(folder)/[x]/ <-- If Exists To Just Get [x].
I'll be quite honest. I don't have the faintest idea
how to do this, while I can do other php without a problem. Once I
know how to go about it I'll be okay.
It's two things I think?
1. see if there's a trailing slash and delete it.
2. Remove the preceding path to /x, the folders and slashes, and
delete them.
and then I have x.

X by the way is the final folder in a website and this grabs it for
me.

<?
$name = $REQUEST_URI;
?>

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...

Add The Contents Of 2 Texbox's
I have designed a form that will display a price (22.34) in
a text box, and another price in the other text box... I also have a blank
text box... Now I want to add both the prices together and get a total in
the bloank textbox..
I got this example off a website sumwhere.. But it does not display the
decimal number, it only displays the whole number

var number1 = parseInt(document.forms[0].CasesSellingPrice.value);
var number2 = parseInt(document.forms[0].AccessoriesSellingPrice.value);
document.forms[0].total.value = number1 + number2;



Getting Address Bar Contents With PHP
How do I get the contents of the browser address bar with PHP - assuming it
is possible?

In javascript it is done with: unescape(window.location.pathname), but is
there a php equivalent?

List Db Contents
can someone help me make a script that will list the information in one colum in my table! See each clan I have has an ID, and CEO and bla bla bla! But what I want done is it to only show the name of the clan in A dropdown menu. So that when users are signing up they can select the clan they want and it well ya you know puts the name beside theres in the table. But can someone make me a script to list all the clans Names and only names not ID, Ceos, and all that other stuff. Code:

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.

Display Contents In Mb/gb
i was wondering if it was possible using php to display how much in mb or gb how many files in  afolder e.g

folder <-- containg 1,000mb of data

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.

Displaying Directory Contents.
Is it possible to display the contents of a directory onto a page with php? Is there a certain function for it?

How Do I Email The Contents Of A Webpage?
How do I email the contents of a webpage?

My project is coming along nicely and I have it almost completed.

It started with putting data into a mysql database and allowing people to
select items wanted from a big list. I now can update the database with the quality wanted and I can generate an email to the person however I cannot get the list of items wanted into the email.

The list is coming from a mysql database based and comes up in a table type
format

My question is how do I get the information from the 2nd page into the body
of an email?

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));
?>

Comparing Array Contents
i'm having a small problem with getting information into a database. Basically, i've got a form with some elements in it, such as:

name phone address

for example. I pass these values to a function which finds out whether the action is associateds with the form is to insert, update or delete info from/to the database (using an HTML "hidden" field.)

The field names in my database are the same as in my form. (name, phone etc...). Using mysql_fetch-field, I have an array with the field names in it. I read the values passed from the form into an array called $values with the form fields as keys ? I would like to set the entry as 'NULL' for each field in which there is no data to enter. I thought the best way to do this was by comparing the contents of both arrays, and where there was a key in $values corresponding to the fieldname, somehow assign the contents of $values to that fieldname in the query.



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?

Size Of Variable Contents...
We are trying to debug a program that queries an oracle database
and reads a LOB.
Somewhere along the line from the db to the screen, an initial cr
gets added.

We can read out the LOB fine using Tcl/Tk, so we know the database
data is correct.

We now like to know when the additional char gets added, between
reading the lob and displaying it.

Set JavaScript Variable To DB Contents
I can get the contents of the my database comments field using PHP.
The comments field may include single or double quotes or other strange
characters.
How do I compensate for these problem characters when I try to set a
JavaScript variable? eg.

Is There A Limit To Array Contents?
I'm building a database interface and plan to take the single-column results of a search and stick 'em into an array to pass them on to the next phase in the database search.

They will be numeric, each value is probably no more than 8 characters, but the array may have as many as 500,000 values. I know i'm new to php, but this sounds like too many to me. Is there a limit (whether official, technical, or simply for user-friendly purposes) or a general guideline for how many values can be in an array? Here's kind of what I mean for clarification:

$array[0] = "00000001";
$array[1] = "00000002";
$array[2] = "00000003";
...
$array[500000] = "00500001";

Will this work?

Checking Form Contents
I would like to verify the contents of a form before inserting the data into a mySQL database. How can I check the contents of the form and return the user to the form if they have not completed all the required fields(with the data they have entered intact). Only after the form is verified to contain all the mandatory data do I want to insert it into the database.

In addition, it would be great if I could highlight the fields that are missing data. Currently, I have a php script handling the submission and insertion. Is it possible to make that submission conditional?

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>";

?>

Downloading Contents Of A Website
What would be the best way to download the contents of a particular website and define all the content/html as a variable? I'm currently using fopen / fread right now but there is a problem, the script will stall when its reading a missing file (404).

Is there a more efficient method besides using fopen / read? If not, is it possible to have the script error when there is a 404?

Check On The Field Contents
How can I make a check on the field contents to make sure what has been entered is a number?

Check String Contents: Can Be Used As Var?
is there anyway to check if a string could be used a variable name. So
return false if the first character isn't a letter or if it contains
spaces etc.

I started writing a function that would do a load of tests because I
couldn't see any easier way of doing it:

<?
function is_valid_handle($str) {
// determines if the string provided can be used as a handle
// such as a php variable or html/css class
if (strlen($str) > 255)) return false;
if (strpos($str,' ')) return false;
// incomplete, needs more tests
return true;
}
?>

but as soon as i realised i would have to use range() to check all the
characters were valid and all that i decided there must be an easier
way. Do you guys know of one or am I just going to have to write it myself?

It was about then I had a great idea maybe if you use the variable
variable syntax you can see if it will return false but unfortunately it
does this:

<?
$foo= &#395;very @#bad variable name'
$$foo = 'Hi!' // doesn't cause error
echo $$foo; // outputs Hi!
echo $5very @#bad variable name; // causes an error, obviously
?>

Seems PHP will quite happily let you store data in a variable of
whatever you like. I guess that's a nice feature. So...any ideas?

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";}

Inserting The Contents Of One Page Into Another
I want to put one php created page inside of another. page1.php PHP Code:
<? 

Listing The Contents Of An Array
how do I list the contents of an array in a select box using PHP. I was hoping there would be a function or something.

Sites Stealing My Contents
I have a growing site that offers statistics and ranking for webmasters. As I expected, some of them started to pull the pages where their stats are, handle them with PHP and show only the items they want to on their sites.
Are there any ways to stop that?

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.

PHP Directory Contents Displayer
I have the following script, which lists files within a specified web
directory (as long as they are valid extension types). It works, but I
would like the file names to be links (i.e. with hrefs) that allow you
to open that file directly from the page. Purpose of the script is
purely to display a list of photos within the directory, with links to
view those photos. PHP is not my strong-point. Any suggestions would
be very gratefully received... Here's the script....

//This function retrieves all files within a directory (non recursive)
and outputs them onto the page
//You can limit the type of files to retrieve, such as images only, as
dictated by the file's extension

function getfiles($dirname=".") {
$pattern="(.jpg$)|(.png$)|(.jpeg$)|(.gif$)"; //valid image
extensions
$files = array();
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)) //if this file is a valid image
echo "$file <br />";
}

closedir($handle);
}
return($files);
}
//EXAMPLE USAGE:
getfiles(); //List all image files within the directory the PHP script
is in
getfiles("/home/myserver/public_html/george"); //List all image files
within a specific directory on the server

Size Of Directory Contents
I want to find the size of all the files in a certain directory. I believe I have to start with: PHP Code:

View Contents Of Directory
I need a script that will display, in a table, all the contents of the folder. Like, for example, its filled with images, there will be a table and in each cell the file name with a link to the actual file. Can someone try to whip this up?

Display Contents Of Subfolders
I am trying to make a script to display contents of a folder and any subsequent subfolders, but I don't know how to move into a subfolder and display the contents.

Viewing The Contents Of A Directory
Is there anyway to view images in a folder using php? I tried asking in perl and a guy replied saying use glob but i dont think we can so is there a way in php.

Determine Contents Of Listbox
How can I determine the values of a listbox, both unselected or
selected after submitting the form:

Code:

<select name="sel1" size="10" multiple="multiple">
<? PHP code populates listbox ?>
</select>

Do I have to use Javascript to determine the contents, like in the
pseudo code Javscript below. But how would you pass the Javascript
return value to PHP?

Code:

function listBoxContents(sel1)
{
var selLength1 = sel1.length;
var valuesPresent1 = new Array(sel1.length-1);
var i;
for(i=0; i<=selLength1-1; i++)
{
valuesPresent1[i]=sel1.options[i].valueOf();
}

return valuesPresent1;
}

Request Url Contents And Parse Xml
I want to accept a movie title into a form field. Once submitted I want to take the search string append to a url and request that url. That url returns xml data that I then want to parse. Code:

Check If A Variable Has Contents In It
I am making a user login system, on the main login page it first gets the contents of a "logged-in" session cookie then sets it to a variable. How can i make something that will check if the variable is empty or not? 


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