Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Php batch file call

Status
Not open for further replies.

hullaballoo

Programmer
Aug 12, 2005
8
HU
Hi!

I'd like to call a batch file from php, which moves a file from a location to another.
But I can't make it... :(
Could someone help me, please?
Thanx

 
It's php 4.0, Windows XP.
The file movement should happen between network drives.

I've tried this:

$output= shell_exec('cmd.exe /c move c:\\test.doc x:\\');
echo "<pre>$output</pre>";

But nothing happens.
If I try this:

$output= shell_exec('cmd.exe /c type c:\\test.doc');
It works.

The "global" problem is to store documents in an Oracle database, and read/write them with a php client..

Any ideas?

Thanx
 
Why not just move the file from within PHP using PHP's rename() function?

This script

Code:
<?php
rename ('c:/foo.txt', 'c:/temp/foo.txt');
?>

quite happily moves the file foo.txt from the root of c: to the directory temp.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I've also tried that.

if(!rename($filename, "../../../orashared/$filename"))
{
echo "failed to move file!";
}

It worked in the web document root of the php server.
But as I said, the file movement should happen between two network drives. I'd like to copy a file from the php webserver to the database server...
Any ideas?
 
This script

Code:
<?php
rename ('c:/foo.txt', 'z:/foo.txt');
?>

works quite well for me.

Even

Code:
<?php
rename ('c:/foo.txt', '//servername/directory/foo.txt');
?>

works


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi!

In this example, the 'c:' and 'z:' drives are network drives or local drives?

I tried both versions:

1. c: local drive on the client machine z: remote drive, mapped in the client machine.
2. c: local drive on the webserver, z: remote drive, mapped in the server machine

None of them worked... :(

The error message doesn't really say anything:

Warning: Rename failed (No such file or directory) in c:\webdocumentroot/pmflow/blob/main/blobwriter.php on line 82
failed to move file!

The code sample:

if(!rename('c:/setup.log', 'z:/'))
{
echo "failed to move file!";
}

Where are the files to move supposed to be?
Is it some kind of security issue?
 
On my system, c:\ is a local drive and z:\ is a network drive.

This line you've posted:

if(!rename('c:/setup.log', 'z:/'))

is problematic. You're literally renaming the file, so you can't just specify a drive letter as your destination. You have to specify a drive letter, directory and filename as your destination. At a minimum:

if(!rename('c:/setup.log', 'z:/[red]setup.log[/red]'))


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
You're very kind that you help me, but anything I do, it doesn't work :(
I've tried your version -> The same error message..

Don't we need to set something up in the php.ini to enable the access to the file system?

The main problem is to move a file from the webserver to the database server, and after that to insert the file to the database as a BLOB. The only thing we need, the file movement, the other things are working...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top