Hi all, New here, so here goes. Trying to make a PHP script to create symbolic links on my server to other in-house servers. I want to be able to give the script input from a file, say sources_add.txt, one line per row, separated by tabs or "||", and the line terminated by "!". Two arguments per row, target and destination. I've been looking around the internet, but as I'm new to PHP I turned to these forums for help. This is a sad attempt, but here's my code so far: ------------------------------------------------------------ <?php $fp = fopen('sources_add.txt', 'r') OR die("can't open file!"); while($row =(fgetcsv($rssc,2000))) { $start = 0; $end = strpos(!); $tar_end= strpos('||') $link_st= tar_end++; $target = substr($row, start, tar_end); $link = substr($row, link_st, end); $creation = bool symlink($target, $link); if ($creation) //print('success!') else //print('failed! check that paths exist and link has not already been made.') } ?> Code (markup): Any help/advice/howtos would be useful. Thanks!
Some advice I'd give you for this: Instead of fopen/fclose, use file_get_contents and put it into a variable. Read through the variable and explode it by the delimiter "!". Foreach the array given from explode() and do the command with it. Also post some example data so I can better understand what you're wanting done. So far, you've done an excellent job for what you want done.
Thanks for the reply Joel. Sorry for the late reply, I was away for the weekend. I'm thinking I could use explode to create an array of data targets and links? array explode ( string '|', $row) Code (markup): Sample data: source_add.txt (target | link !) /srv/docs/policy.pdf|/var/www/html/docs/! Code (markup): Essentially, I want to create a PHP script that can be called to create the desired symlinks. I was hoping for it to be like a batch file I could run via a web browser to read the txt file and clear the lines of text as it successfully creates the links.
You could explode by the !, then trim the extra \n off the front, and do a foreach to the exploded ! array. Then, you explode each | and do something like: shell_exec("ln -s {$paths['0']} {$paths['1']}"); PHP: -- EDIT: I forgot there is a symlink command in PHP: symlink($paths['0'], $paths['1']); PHP: