?
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
Medium Priority
?
194 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 2000 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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

777 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