Re: [PHP] FTP problem..
On Tue, Apr 24, 2001 at 10:10:58AM -0400, Chad Day wrote: I'm trying to write a script to ftp the contents of one directory structure onto another server.. I'm having problems recursing the directories, either it a) doesn't do it or b) gets stuck in a loop. Here's the function I'm having the problem with.. Directory recursion has angered me many long nights. Here is what I finally came up with, which works perfectly. This should be easily changed into what you need.. it's just an example of the logic. ;) This was meant to run from the command line with /usr/bin/php -q ;) $base = $argv[1]; $i = 0; $directory[$i] = array ($argv[1]); while (1) { if ( @ is_array ($directory[$i])) { $subdirs = ; foreach ($directory[$i] as $dir) { if (($dir_handle = @ opendir ($dir))) { print (Reading $dir\n); while (($file = readdir ($dir_handle)) !== false) { // Drop these two, else we'll be no better // than glibc's glob() ;) if (($file != '.') ($file != '..')) { if ( ! ereg ('^/', $dir)) { $temp = $base . $dir; } else { $temp = $dir; } if ( ! ereg ('/$', $temp)) { $temp .= '/' . $file; } else { $temp .= $file; } // Consider dropping symlinks right here, // or treating them as a normal file. if ( @ is_dir ($temp)) { $subdirs .= $temp . ','; } else { print (\t$file\n); } } } closedir ($dir_handle); } } $i++; if ($subdirs) { $directory[$i] = explode (',', substr ($subdirs, 0, ((strlen ($subdirs) - 1; } } else { break; } } Hope that helps a bit. I know that was one of the most frustrating things I've ever tried to figure out (in any language). It's certainly not perfect.. you will probably need to add a few more string checks to it, but the basic logic seems flawless to me. Good luck! ;) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] A simple problem!
On Tue, Apr 24, 2001 at 11:24:26PM +0530, Subodh Gupta wrote: Can You figure out the mistake here...?? print EOQ tr\n td valign=top align=rightbfont color=#$colour[$colouroffset]$name:/font/b/td\n // The problem is here.. the value of $colour[$colouroffset] is not td valign=top align=leftfont color=#$colour[$colouroffset]$dbvalue/font/td\n // getting substituted. Can you tell me why?? /tr\n\n EOQ; This is more than likely due to the variable being enclosed in 's, although I can't say for sure, as I've never used print() in this manner. Try adding the '#' to the actual $colour[$colouroffset] value, then simply replace #$colour[$colouroffset] with $colour[$colouroffset]. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] ereg_replace
On Tue, Apr 24, 2001 at 06:21:20PM -0400, Wade wrote: I am attempting to do an ereg_replace(), but the charachter I want to replace is a \. Any Ideas how I make the following work? $F_name = ereg_replace (\, , $acc_fname); echo $F_name; Thanks, Wade use \\ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] random letters and numbers
On Mon, Apr 23, 2001 at 11:10:48PM -0700, Randy Johnson wrote: Is there a way to generate a random set of characters ranging from 8 to 12 characters and numbers where it is crucial that the letters and numbers are truly random because I need to create temporary files for people to download information. Any links/suggestions would be greatly appreciated Thanks Randy Also check out the tempnam() and tmpfile() functions, as this is exactly what they were made for ;) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] is_link() behavior
Forgive me for my ignorance, but I've noticed some unwanted behavior (IMO, at least) with the is_link() function. Given the simple code.. if ( is_link (/tmp/this_is_a_symlink) ) print (Success\n); and the file.. lrwxrwxrwx 1 root root 5 Apr 23 21:19 /tmp/this_is_a_symlink - /bin/ the above obviously prints 'Success\n'. However, if I break the symlink, with something like the following.. lrwxrwxrwx 1 root root 4 Apr 23 21:21 /tmp/this_is_a_symlink - foo the script fails with.. Warning: stat failed for /tmp/this_is_a_symlink (errno=2 - No such file or directory) in ./test.php on line 3. The file /tmp/this_is_a_symlink is still a symlink, so it seems to me that the is_link() function should still return true, whether or not the symlink's target exists. Is there perhaps a function I have yet to discover that provides that behavior, without verifying the link's target? I ask this because much of linux's /proc contains (intentionally) broken symlink's and is_link()'s behavior is making the scouring of /proc very difficult on me. ;) Thanks for any input.. J. Jones -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] file_exists with remote file???
On Tue, Apr 24, 2001 at 12:20:01AM -0300, Paulo - Bruc Internet wrote: Can anyone help me? The sintax of function file_exists is: if(file_exists(t.txt)) { print... } Does anybody knows how can work with remote files? This is not working: if(file_exists(http://www.ttt.com/t.txt;)) { print... } Thanks for any help, Paulo Roberto Ens - Brazil Bruc Sistemas para Internet Ltda mailto:[EMAIL PROTECTED] http://www.bruc.com.br Diversão ou Cultura? CuritibaWeb.com - O Melhor Guia de Curitiba! http://www.curitibaweb.com From the manual.. file_exists() will not work on remote files; the file to be examined must be accessible via the server's filesystem. Try something like this instead: if (($fd = fopen (http://url/file.ext;, r))) { print... } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] is_link() behavior
On Tue, Apr 24, 2001 at 05:31:04AM +0200, Martin Skjöldebrand wrote: Warning: stat failed for /tmp/this_is_a_symlink (errno=2 - No such file or directory) in ./test.php on line 3. Do you have permission to read the /tmp catalog? Otherwise you may get that error I suppose. M. Yes.. the script was executed as root, so permissions aren't an issue. ;) The error, I believe, is generated from is_link() trying to do a stat() on the link's target, which doesn't exist. The symlink is broken the second time around (foo doesn't exist). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]