Solved

I have a large collection of files I need to rename - but the PHP functions "copy" and "rename" are disabled on my server.  Is there an alternative I can try?

Posted on 2008-10-19
4
191 Views
Last Modified: 2008-10-19
I have a large collection of files I need to rename based on an ID number in my database.  This would be extremly simple to do with a "rename" or "copy" function, but the server I am hosted with seems to have these two functions disabled.  Is there another way of doing this through PHP?  I don't know much about batch (DOS maybe?) files, but maybe there is a way that PHP could output some sort of batch script so I could rename my local files instead?  I have XP Home, so unfortunatly I can't setup a local host and just run the PHP script on my own machine.

Liz
0
Comment
Question by:maeve100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
Scripting_Guy earned 500 total points
ID: 22752910
why can't you? Just download PHP for Windows (http://www.php.net/get/php-5.2.6-Win32.zip/from/a/mirror) and extract it to a folder, like c:\php.

Then open a cmd window and use as follows:
c:\php\php.exe -f c:\script\script.php

PHP scripts on Windows do not need a line for the interperter if called with php.exe, so delete the #!/usr/bin/php line if it is there. Just start your scripts with <?php
0
 

Author Comment

by:maeve100
ID: 22753053
The local renaming of the file worked - but I can't seem to connect to my online database to grab the name I need to rename the file with based on the ID, Scripting_Guy.  Should I be able to run a local file and have it connect to a database online?  Maybe its a simple matter of syntax?  I am positive the dbconc.php file is working correctly.
<?php 
 
require_once ('dbconc.php'); // Connect to the db.
 
// Make the query.
$query = "SELECT * FROM list WHERE list.id = 9";
$result = @mysql_query ($query); // Run the query.
$row = mysql_fetch_array ($result, MYSQL_ASSOC);
 
$file = 'tmp_file.txt';
$newfile = $row['OID'];
rename($file, $newfile);
 
mysql_close(); // Close the database connection.
?>

Open in new window

0
 
LVL 3

Expert Comment

by:Scripting_Guy
ID: 22753237
This depends on your database server, but if you're on a shared host i doubt it.

You can try by change your mysql_connect statement from "localhost" as server (presumably) to the external ip of your server.

But as mentioned, i doubt that this will work. So I would export the data from your online database (e.g. into a textfile) and work with that textfile on your local machine.

If you'll give me a bit more details about your current db scheme (what is the old file name - what is the new one) I'll help you with that if you need any help.
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 22753478
Consider the following(note the permissions on "somedir" in the example allows for the writing and deletion of files):
<?php
$oldname='somedir/oldfile.txt';
$newname='somedir/newfile.txt';
$fp = fopen($newname, 'w');
fwrite($fp,file_get_contents($oldname));
fclose($fp);
unlink($oldname);
echo 'done';
?>

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question