开发者

Shell access to PHP scripts on localhost?

开发者 https://www.devze.com 2023-04-01 09:24 出处:网络
I am curious, how can I access a file like this below开发者_高级运维 on my localhost dev server?Is shell even the correct term?Please help

I am curious, how can I access a file like this below开发者_高级运维 on my localhost dev server? Is shell even the correct term? Please help

https://github.com/mikesmullin/CSS-Sprite-Generator/blob/master/css-sprite.php

Update:

I am wanting to know how to access PHP files with Cli


You might want to check out the php.net tutorial, then maybe post specific questions if faced with a particular problem.

Calling a php file is as simple as:

php my_script.php


If your file is called css-sprite.php, then:

  1. Give this file execution permissions (chmod +x css-sprite.php should do the trick).
  2. Go to the directory of this file and call it directly: ./css-sprite.php.

As you probably see within the example you have provided, the first line contains path to the interpreter - this is similar to the way Python scripts inform about the interpreter that should be used to execute specific file. You should update it to the path that is working for you - just see Example #1 from the documentation:

#!/usr/bin/php
<?php
var_dump($argv);
?>

Does it clarify what you wanted to know?

EDIT:

Of course you can execute your files using command php myscript.php, but the above mentioned solution shows you another way to do that.


Sure you can, and you don't to run a shell process for that. That code is PHP, and if you want to run it from PHP, all you need to do is include it.

Now, the only problem might be how you pass parameters into that script execution. You have 3 (probably more) possibilities:

  1. Modify the script so it doesn't use $_GET for the parameters. I found 11 occurrences of "$_GET" in that file, so this should be easy. You have to check the license, though, if you are allowed to edit the file, and on which conditions.

  2. Set the $_GET variables before including the script. $_GET is a superglobal, so it will be available in the script. But setting $_GET is considered bad practice as you might override some parameters you expect yourself, and in bigger projects this might cause strange results...

  3. Look at the script you linked, look what is being done, and do it yourself. You will save a lot of code (you probably only need 30 of the 300 lines of that file to do what you want) and it will be your own code with which you may do whatever you want. Just don't copy if the license prohibits that. Only crib :P

The latter option is IMHO the best way, because you learn how to do it yourself correctly.*

0

精彩评论

暂无评论...
验证码 换一张
取 消