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
193 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

717 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