File Names In Directories
On my current website I have gallery pages with links to different
galleries within that gallery section. The problem is, that I have to
manually edit every single page when I want to add a new page so that every
page now has a link that includes the new page number.
Now I have been thinking that surely PHP could be used to automate this
instead of me doing it every time I put a new gallery page online.
What I'd like to know is if it is possible for PHP to read a file name,
then use that to "echo" it into the HTML, then go to the next file name -
do the same, until there are no more like sounding filenames in that
directory.
So for example, I have gallery01, gallery02, gallery03 webpages.
I ask PHP to look for a match for "gallery", then add the file number "01",
and echo it to the HTML page, and then do the same until there are no more
"gallery" pages to be found in that directory.
If possible, scould someone point me in which direction to do this (I don't
need / want a complete solved solution :) ).
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
File Directories
I searched the forums and didn't see an answer to this question. I need to store a lot of files on my server, ~100 000 files. The files range from 800kb to 30MB. Would it make a difference in search time for PHP to find a single or multiple files if all the files were in one directory, or should I map them over several directories (e.g alphabetically)?
File Access To Directories Below Document_root
I need some input on whether this can be done. Server Folder Structure: httpdocs (all the web docs) web_users (all ftp accounts) snorider (specific ftp account folder) On my server I have set up a web_user (specific ftp account) I have uploaded files to that directory, and now I am trying to use fopen to open them and read from them. Now I can access them through a link like: href="/~snorider/file_I_want.php" But I'm having problems using fopen the same way. The overall purpose of this is to have user specific download files which can be uploaded to the server without having to connect to the server with full access to all the website files. Does anyone know of a way to get fopen to open the files inside "snorider" while using a LOCAL file path?
Including A Standard File In All Directories
I have one layout page that all directories use on my website. How can I make it so that no matter where the file is, the server will always include it. I cannot use direct paths because php will not allow it, and I can't specify the directory for each file. Example. Layout.php includes files/header.php which includes lib/main.lib. in Pages/Path/index.php I include ../../Layout.php. Than Layout.php's includes are all messed up.
Directories, CHMOD, And File Uploads
1) Is the only way that doesn't involve Databases to upload files is to CHMOD a directory to 777? 2) What are the risks of CHMODDING a directory to 777? 3) What are the risks of CHMODDING a .txt file to 777? 4) How can I find the name of every .txt file in a directory?
Getting File Names On Another Server With PHP
My ISP provides me with minimal space on a dedicated server running PHP, and 250MB on a separate HTTP server. I'm trying to make a gallery using PHP. The script is held on the PHP server, and the thumbnails and images are on the separate HTTP server. Ideally I'd like to be able to get a listing of the contents of the HTTP server where the images are stored. I want to do this so that when I add/delete/change images, the dynamic nature of the site just picks up the new files and I don't have to maintain a separate database of the image names and where they're stored.
File Names Into Array
right so im in the midst of creating a gallery for a friend of mine, i have most of it right, but when i get the file names from the directory and into an array i have the ".." and "..." as the first two elements, any ideas? my getImages functions is simply as follows: #PHP function getImages() { global $images; $mydir = opendir(images); for($i=0; $i<10; $i++) { $entryname = readdir($mydir); $images[] = $entryname; echo("<br>"); } #PHP
Reading File Names
Im writing a php file that will upload pictures in a remote directory. Im actualy doing a buletin board,and i have a mysql table that has subjext message date and entries(key) columns. I want the user to be able to aslo upload a image when posting a message. So I figured the best way to do this is to upload all files in a dirr and add the column 'image filename' to the mysql table for each entry. Im not sure how to read the file names for each entry. My guess was to use $image = basename($path); but how will it know to store differet file names for each entry in the table. Does anyone know ?
Reading File Names In A Directory.
I'm quite new to PHP, just getting my feet wet really, and I was wondering if I can scan a directory? ie. Counting all files in a certain folder with a ".txt" extension or maybe all files in a folder that contain "news" in it's name.
Get A List Of File Names From The Server
im working on a flash interface that needs to call a script that reads a directory on the server and returns the names of the files that are there. what would the php command look like that would get the file names?
Problem Passing File Names
I'm using the following function to display a list of files in a directory in a HTML form that allows the user to delete files. Look at the echo line. The links work fine, taking a user to ../directory/file.extention as expected. However, the value in the name field of the input tag gets passed through POST as /_/directory//file_extention, which messes up my unlink function. The strange thing is I'm using "/$dir/$file" for both of them, so POST must be doing something to my string. function checklist_dir($dir) { if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if (filetype($dir . $file) != dir) { echo "<input type="checkbox" name="/$dir/$file" /><a href="/$dir/$file">$file</a><br />"; } } closedir($dh); } } }
Regular Expression To Catch File Names
Trying to figure out a regular expression to catch file names in a string, so anything matching the patterns of "_-1a" with a possible "../" before that and a possible "/" after but ending with a file extension ".gif" using letters or numbers, so far i've come up with this which works with everything i've tested... "^[../]*([-]|[_]|[0-9a-z])+[/]?([-]|[_]|[0-9a-z])*.[0-9a-z]+$" but because i'm new to this was wondering if i've missed anything, by the way i only want this to work with relative file paths not absolute so that should'nt work!
Make Uploaded File Names Unique?
I have been working on an upload script and it occurred to me that there would be a problem if someone tried to upload a file that already exists. Instead of producing an error message telling the user to rename their file, that i should append something to the uploaded filename to make it unique. I'd thought for the purposes of the system i am making (relatively low number of users) that a timestamp down to the second would be a sufficient measure to ensure that this problem does not occurr. Code:
Setting Variable Names Using Field Names?
I'm having trouble creating dynamic variables using field names. Basically I got a heap of fields named after Players and I want to grab the field name and make a variable called it while assigning it a value from a post variable which is also the player name. This is the code I'm using: $result=mysql_query("SELECT * FROM playerstats"); while($fld = mysql_fetch_field($result)) { if ($fld->name!='match_id' && $fld->name!='opponent' && $fld->name!='map') { $fld->name=$_POST[$fld->name]; } }
Dont Want The File Names In The Browser Address Field
Is there a way in PHP where the file name do not appear in the browser address field. eg. the url of a file is : http://www.somedomain.com/somepage.php. but when a link to this page is clicked, only http://www.somedomain.com should show up in the browser address field.
Creating Directories In Directories
I'm building a document management system and I've hit a snag. I'm relatively new, so this might be obvious to someone else. A user can add folders into the system (kinda like Windows Explorer) and then add folders IN those folders. I have a database set up to track the child/parent relationships but I'm having trouble with the actual creation of the directory on the server. I pass the "add folder" script the NAME of the new folder as well as the PATH of the new folder. If I'm in the root directory and I add a "TEST" folder I pass "TEST" as the folder name and "" as the path, because we're adding at the root. If I've added "TEST" and I want to add "IN TEST" inside the "TEST" folder I send "IN TEST" as the new folder name and "TEST" as the path. My code then adds a "/" and calls mkdir. So the path passed to mkdir is "IN TEST/TEST". Code:
Sub Directories
What i would like to know is how with php can i create a subdirecty and copy some files into there?
Uploading Directories ?
Is there any way I can simply allow a user to upload an entire directory through php without selecting the files one by one ?
Create Directories On The Fly...
Just curious to know is it possible to create directories on the fly? What I have done is created a script when you can add categories and subcategories, but what I would like to do is create a directory physcially within that category. For instance using the mkdir command using linux. In a way traversing through and creating a directory. An example would be: If I created a category called business and econony then it would display this in the address bar. http://www.domain.com/Business_and_Economy Then perhaps under Business and Economy, a category called Accounting, then it would display the following: http://www.domain.com/Business_and_Economy/Accounting/ Hopefully I'm making some sense here. Heres the code: function maketree($rootcatid,$level) { $sql="select catid,cat_name from quiz_category where parentid=$rootcatid order by cat_name"; $result=mysql_query($sql); while (list($DBcatid,$DBcatname)=mysql_fetch_row($result)) { $width=($level+1)*24; $display="<img src=http://www.domain.com/spacer.gif border=0 width=$width height=12>"; if ($DBcatid==1) { $display.="<input type="radio" name="quest_type" value=$DBcatid checked>"; } else { $display.="<input type="radio" name="quest_type" value=$DBcatid>"; } $display.="$DBcatname<br> "; echo $display; maketree($DBcatid,$level+1); } } if ($submit=='Add New Category') { if ($new_cat!='') { mysql_query("insert into quiz_category (parentid,cat_name) values ($quest_type,'$new_cat')"); # need to create directory here echo "<br><br><center><b>New category entered</b></center>"; } else echo "<br><br><center><b>New category name must be entered</b></center>"; }
Fopen() With Directories
I am attempting to create directories using a form, a user submits the directory name and the directroy is created. I am attempting to use fopen to create it, but it doesn't seem to be working. Is there a way to use fopen()? Also, could opendir() be used instead? Code: <form action="create.php" method="post"> Site Address: <br> <input name="subdir" width="30" type="text"> <input type="submit" value="create"> </form> PHP Code:
Virtual Directories?
Virtual Directories? I've been working with ColdFusion for my real job and sticking with PHP for my side work and have a question. In CF, they have virtual directories you can set up that you can use the address of mydomain.com/admin and have it access files from another location on the same server thisdomain.com/clientadmin I was wondering if there is something similar to this in PHP. I run a reseller account on a server and can access databases from different domains, so I was hoping this could be possible. If anyone has any ideas, please let me know.
Traverse Directories
My problem is that I can't find a way of referencing files and includes statically. I have to change each page reference so that when it is referenced it references the correct document. As I want a central location to keep all my most used 'includes'. So if I change a scripts location I also have to change the script it's self to point to the correct documents. This is a problem when the directory structures hierarchy keeps changing. Also HTTP referencing is out as the scripts will not all be run on the same servers.
Converting ?PID=whatever To Directories?
I've got a product directory with a product detail page for all products. The way the product page is displayed in the address bar is productdetail.php?PID=# Would it be feasible for a newbie like me to do so that instead of putting in the question mark it's in directories similar to Amazon?
Different Timezones In Different Directories
I have a strange problem. Iset up php 5.1.6 on my Solaris10 box and after that i get errors on my webbpage: "Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We had to select 'UTC' because your platform doesn't provide functionality for the guessing algorithm" I searched a little and foun out by setting up date.timezone in php.ini it works. Bur then I have to recompile php for support of zlib, and after that, I get the error again. Now I found out the following: # pwd /usr/local # php -i |grep timezone Default timezone =Europe/Luxembourg date.timezone =Europe/Luxembourg =Europe/Luxembourg # # cd .. # pwd /usr # php -i |grep timezone Default timezone =UTC date.timezone =no value =no value How is it possible that, when I'm in /usr/local the settings are OK, and in all other location the settings are not. Here header output of phpinfo: PHP Version 5.1.6 System SunOS my-web 5.10 Generic_118844-19 i86pc Build Date Nov 5 2006 16:24:04 Configure Command './configure' '--prefix=/usr/local' '--with-mysql=/usr/local/mysql '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-zlib=/usr/local'
Copy In 2 Directories
I've got a simple question. Is it possible with the command "copy" upload a file via browser on two different directories? I use copy copy("$file", "/directory1/$superdat_name")
Sync Directories
I have a php script on a cron job running every half an hour that FTPs to a given server and downloads files, heres a list of everything it does: 1. Checks file names in the FTP directory with a database table 2. Downloads any new files and imports the file information into that table 3. Uploads all the information inside that file into a different database table 4. Deletes file on the local machine that was downloaded, as to not take up space Now, the FTP directory keeps a full 60 days worth of files which is about 8640 files, everything so far works perfectly, efficiently and doesn't need to be changed. However I want to add a function, in everything it does I want it to check if any of the files in the database have been deleted on the FTP server. As to have only the 60 days worth of file records in the table.
Trying To Get All Directories In A Site Into Array
Thanks for reading. I'm trying to get an array of all the directories in my website. So, it reads the first level, then goes through each first level to find the second, and so on. I'm hoping to get all the first level in one array, all the second level in another and so on. I'm working with this code which does fine for the first level, but can't seem to get it to work for multiple levels without hardcoding everything in: PHP Code:
Protecting Files And Directories With Php
I've got a situation where i have a directory called "example". In this area i have three files, an index page that has a form on it in to which user's can authenticate, a page displaying either success or failure and if success redirects to a downloadable file. I don't want this downloadable file to be had by a direct url access, user's should have to authenticate to get it. I want to use php4 for this and if possible since this is a lightweight requirement i don't want to implement a database solution.
Safe Mode / Directories
I created a directory with PHP mkdir (mode 0777). Then I try to move_ulpoaded_file() to move a file into this directory. I get an error: Warning: move_uploaded_file(): SAFE MODE Restriction in effect. The script whose uid is 1999 is not allowed to access /home/www/ww4592/html/fs/PHP/Dateien/Bereich_1/NEUER_ORDNER owned by uid 33 in /home/www/ww4592/html/fs/PHP/File.php on line 57 The webspace is at a webhost-company, not on my own server. I think I understand the restrictions of SAFE MODE, but I do not understand why a script has another uid than a directory created by the very same script! Is the error above the "normal" bevaviour if SAFE MODE is on? If it is: That is a drastic limitation. If I say to a client "I need webspace with PHP" and I get that SAFE MODE-stuff would it not be right to say that that is no fully working PHP-Webspace? I mean a webspace that does not allow a directory to be created and a file moved into it does not really support PHP -- it's a joke! Any opinions?
Copying Entire Directories
I need to copy all of the files from one directory to another. This has to happen on the fly. The files that are being copied are actually templates for another site that will be created. I have seen the example on php.net under the fopen section but it doesnt work.
Problems With Changing Directories
im trying to make a script that will check two files from inside a directory. The directory is located two folders above where the main script is located. I have tried to change the directory, and load the files into an array, but it doesnt seem to change the directory at all... i have found this out by displaying the directory after i "change it". PHP Code:
Making Directories AND Accessing Them
Does anyone know if it's possible AT ALL to do the following: - make a directory X - create a subdirectory Y in it. - and then put a file in X (or Y) and it should run with SAFE MODE on. After surfing some forum, my conclusion is that is is not possible with PHP. I hope that somebody can prove me wrong.
Creating Multiple Directories
I'm trying to simultaneously create two directories. From a form, the user will be prompt to name a directory and from there the PHP code will create the directory that the user named. When that direcotry is named I am trying to create another directory with the directory that was just created. Is this possible? Here is my code:
Blogs And 'virtual Directories'
Throughout the past few years, I've been working on a personal blog that I've written using PHP. I recently noticed that a lot of blogs support the following URL syntax: /archives/2004/04/03/ /archives/2004/03/ /archives/2004/ and so on and so forth. The thing is, they obviously don't have an actual HTML or PHP page in that directory; I doubt even that those directories actually exist. My guess is that they are doing some sort of URL re-writing using .htaccess in combination with perhaps a single PHP page that takes in parameters as a GET query. It's just a guess, of course. The thing is: I really have no idea how they are doing this. So, how would I implement something like this on my site using Apache and PHP? What is the technical term for this style of 'URL re-writing' even called? I don't mind doing a little research on my own, but I can't seem to nail down exactly what keywords I need to search for in the first place!
Including Files In Other Directories
I have some code running on windows on my local machine that uses the jpgraph image library. I include the jpgraph libs using include ("C:Programmingphpjpgraph-1.14srcjpgraph.php"); I am trying to get this code to run on my web host's unix server, with no luck. I put the folder (jpgraph) containing all the jpgraph libs in the same directory as my php code. I have tried all of the following: include ("/jpgraph/jpgraph-1.14/src/jpgraph.php"); //(relative path) include ("jpgraph/jpgraph-1.14/src/jpgraph.php"); //(relative path without leading slash) include ("/usr/www/users/mysite/jpgraph/jpgraph-1.14/src/jpgraph.php"); //(absolute path) include("http://www.mysite.com/jpgraph/jpgraph1.14/src/jpgraph.php"); //(url) include ("http://" . $_SERVER['HTTP_HOST'] . "/" . dirname($_SERVER['PHP_SELF']) . "/" . "jpgraph/jpgraph-1.14/src/jpgraph.php"); None of these have worked. Does anyone know the proper technique to include files in other directories when using Unix or Linux? Keeping all php files in the same directory is not feasible.
Sorting List Of Directories
If I have a list of directories in the format of month year date, like Jan0213, Dec0215 and so on, then I how do I sort them.
New Directories Have Incorrect Permissions
I'm building an FTP site. I am manually creating my root folder via an FTP programme and setting the permissions to 777 (which I believe is required). When I check who the owner of this folder is, its 32414 (As far as I'm aware, I don't need to take any notice of what this means). I have a form on the site which people can fill out to create new directories, which will result in the following code being run: if ($result_folder = mkdir($path.$id, 0777)) { # if the new folder was created, do this: $file = 'index.php'; $file_copy = $path.$id.'/index.php'; copy($file, $file_copy); echo '<p>Thank you '.$creater.', the folder ''.$name.'' has been created.</p>'; echo '<p>Would you like to <a href="add_a_folder.php">add another folder</a>?</p>'; } When this is done, I notice that the actual permissions of the new subdirectory are not 777, but instead are 755, the owner is 99. This means that I can't manually delete the folder via my ftp programme and my domain will become untidy and crowded. Do you know how to get the correct permissions to be setup, and if I need to specify who the owner is?
Reading Directories, Populating Select Box
Can anybody tell me how to read through a directory, get the file names and populate a select box(pulldown menu) with these names? I know how to loop through a directory using something like this: while ($files = readdir($handle)) { $ext=substr($file,-4); if ($files != "." && $files != ".." && $ext == ".php") { do some wild and crazy stuff here; } } It's the populating the select box (pulldown menu) while doing this that I need the help on.
How To Read Files From Directoiries/sub Directories
I am new to PHP and doing a project. I want to read all files from all directories/sub directories starting from the root of the web site. ie. I want to get the root directory programmatically. I am using linux. The purpose of the file reading is to do an internal searching. Could u give me a sample code.
Project, Files And Directories Organisation
I am searching a kind of software engineering document about PHP. This document should give advices about PHP project organisation (structure of files, directories, names). Shall I organize hierachically and how (a main directory, a directory for php files, for html files ...)? How to use "base" request in HTML under PHP and that sort of things.
Pass Word Protected Directories
I don't know if this question should be ask here or directed at my website server. Part of my web site is behind a user name, pass word protected directory made with the hosts routine. EV-one in this case. When I enter my name password to enter the directory and then leave to go to other parts of the website, I do not have to enter my name password when I come back. When I go to other websites and come back to this protected directory, I do not have to enter my name password. The only time I have to enter my name, pass word is after I have closed the browser. Is this normal. Is there code I can add to close that particular path? Is this a cookie issue and can I control that cookie? I do remember when I set this up it ask 'ssl' or 'non-ssl' and both were checked. I unchecked one and don't remember which and have not gone to look since I started this message.
Open Directories Read Into Array
how to open directories that are array elements and extract an html file out of each?? The script below opens a certain directory, variables passed from another script, checks if this (day) directory exists and reads its content, which are subdirectories, into an array. My problem is that I don't know how to access the files within those subdirectories. The subdirectories contain images and html page and I would like to extract the html page. I certainly need ereg to match the html file, but I cannot access the files within the subdirectories. The result should be a link subdirectory/html page. Code:
Creating Directories From MySQL Query
I'm trying to create a subdirectory within a directory. The directory uses $rows['link'] from the category table, and the subdirectory uses $subcategory2 from the subcategory table. The directory that gets created is always based on the last record in the table, rather than the parent. I have tried using another query, but only the subdirectory gets created then......
Setting Cookies For Multiple Directories
I'm having a little trouble getting 'sitewide' cookies to work. Code: setcookie ("facilityidcookie",$facilityid,time()+14400,"/"); This is supposed to set a cookie from the root level and have the cookie available for all directories below root. For some reason it does not work as intended. The cookie works great for root level docs, but all sub directories do not see the cookie.
Private And Public Document Directories
I will be building an application using PHP & MySQL where recognised users (controlled using PHP4 sessions) are able to upload documents to the web server through a form. Users will be able to indicate whether the document they are uploading is for private (ie. intranet) or public availability. Obviously making a document public is the easy part. What I trying to decide right now is the best way 'protect' documents that have been marked as 'private' from public view/access. I could use .htaccess/.htpasswd as a simple restriction over the entire intranet directory, and have the private documents copied into this directory of a sub-directory. BUT since I've got mutliple users who want to be able to login with their own usernames and passwords (AND be able to change their own passwords as one of their member functions), then this solution is not sufficient - UNLESS I am able to manage the .htpasswd file at the same time as a registered user manages their password/profile on the MySQL database... So using PHP4 sessions I can quite happily control who gets to view the Intranet/private web pages (which will have links to the URLs of the private documents), but this won't protect access to the private documents if someone who is not logged in simply enters the correct URL for one of these documents. The apache module mod_auth_mysql would do the job nicely, but my hosting service will not install it for me.
|