Executing Shell Commands

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ragonz
    New Member
    • Jul 2008
    • 24

    Executing Shell Commands

    I want to execute group of cmd command from php

    for example, i'm going to open an image file from d:\pictures\
    and "temp.jpg" is the file's name

    In cmd, it's just about :

    [code=dos]cd d:\pictures <enter>
    temp.jpg[/code]

    how 'bout in PHP??

    here's what i've tried

    [code=php]$command="cd d:\pictures";
    system($command );
    $command="temp. jpg";
    system($command );[/code]

    but it's not workin'...

    i really need help for this, THX b4
  • Brosert
    New Member
    • Jul 2008
    • 57

    #2
    I think the problem is that cmd (the Windows Command Prompt) knows as much about file tuypes as windows itself (obviously). This means it AUTOMATICALLY decides which program to open the picture with....

    PHP deals with the actual command line on the SERVER machine (and quite often a UNIX one) - "temp.jpg" is not actually a command, it is merely a file. You need to decide what you want to do with it.

    I'm not really sure that you want to open this file in 'picture viewer' anyway - perhaps if you explained what you are trying to do, someone may be able to suggest a solution. If you are actually using this code across a network, you need to remember that it runs on the server - so it doesn't know what programs you have on the client - and shouldn't assume.

    Comment

    • ragonz
      New Member
      • Jul 2008
      • 24

      #3
      Originally posted by Brosert
      I think the problem is that cmd (the Windows Command Prompt) knows as much about file tuypes as windows itself (obviously). This means it AUTOMATICALLY decides which program to open the picture with....

      PHP deals with the actual command line on the SERVER machine (and quite often a UNIX one) - "temp.jpg" is not actually a command, it is merely a file. You need to decide what you want to do with it.

      I'm not really sure that you want to open this file in 'picture viewer' anyway - perhaps if you explained what you are trying to do, someone may be able to suggest a solution. If you are actually using this code across a network, you need to remember that it runs on the server - so it doesn't know what programs you have on the client - and shouldn't assume.
      here's my problem

      i want to load data by using sql loader into oracle table.

      The default directory for sqlldr is c:\documents and settings\user
      while the data is in inetpub folder. The data come from uploading process in PHP, i tried to copy the upload files into the default directory for the sql loader but, it didn't work. and the uploaded files are in the inetpub folder.

      It'll be easier if i could copy the uploaded files into sqlldr directory, coz i don't need to (change dir [cd ] in cmd line) just execute the command. But, since they're not in the right folder, i need to chage the dir first and then execute the command (i have to execute it when it's in the right dir). Those are 2 different commands, but related one another.

      So..?? how 'bout it??
      Thx.

      Comment

      • Brosert
        New Member
        • Jul 2008
        • 57

        #4
        Assuming the PHP is running on a UNIX server (which is quite likely, I think), you can use:
        Code:
        cp {fileoriginal} {filenew}
        to copy a file
        or
        Code:
        mv {currentFile} {FutureFile}
        to move the file

        This should be able to be executed in PHP using something like:
        Code:
        system('mv ~/temp.jpg ~/otherPath/temp.jpg' );
        Note: I assume that executing system commands has not been disabled on the server you are running the PHP on - you will get a reasonably clear message if it has been disabled....

        Comment

        Working...