I have two PHP versions that I want to execute depending on the situation. I have setup PATH so that when I type php there is executed the right version of PHP in the folder C:\xampp\php.
However, I also have an older version of PHP in the folder C:\old-xampp\php. Of course, I can't add also that folder path to PATH as there would be two folders with a file with the name php.exe and used would be always php.exe in first folder in PATH.
At the moment I have to type C:\old-xampp\php\php my-command-here every time I want to execute my old PHP.
Is there a way to create a .bat file in a PATH folder with the name old-php.bat that would act as if I typed C:\old-xampp\php\php?
I am open to another method to do it too.
There can be written into a batch file old-php.bat stored in a folder of which path is listed in string value of environment variable Path the command line:
#C:\old-xampp\php\php.exe %*
%* references all arguments passed to the batch file exactly as passed to the batch file. This is explained by the usage help of command CALL output on running call /? in a command prompt window. Argument 0 is the string used to start the batch file which is not included by %*.
It would be also possible to create in a folder of which path is listed in string value of environment variable Path a hard link or a symbolic link with a name like old-php.exe which links to C:\old-xampp\php\php.exe by using once MKLINK.
I'm successfully able to execute with this following command:
system('C:/Program Files/PSPP/bin/psppire.exe ');
i want to do something like opening a file through this exe e.g.
system('C:/Program Files/PSPP/bin/psppire.exe, C:/xampp/htdocs/csv/txtfiles/PSPPfile.txt');
This above command should open txt file in psppire.exe!
Help me out! Thanks.
For Windows OS(according to your example) - separate path for executable file and path for target file with space.The working example is shown below:
system('"C:\Program Files (x86)\Notepad++\notepad++.exe" "C:\arsetup.log"');
It looks like you have a comma in the name of the command you're using. That's a problem in and of itself. I don't think the name of that executable is "pspire.exe,".
Also you may want to quote the different paths because they contain spaces. So it maybe should become
system('"C:\Program Files\PSPP\bin\psppire.exe" "C:\xampp\htdocs\csv\txtfiles\PSPPfile.txt"');
Also you should note that I used backslashes, which is the correct directory separator for Windows. To make this universal you can use the constant DIRECTORY_SEPARATOR
I have the following code:
<?php
$path = "/path/file/";
$pathout = "/path/out/file/";
exec('convert '.$path.'test_pdf.pdf[0] '.$path.$value.'.jpg');
?>
I want to know if there is a way that ghostscript generates the output JPG and at the same time also generates an new output folder?
I believe it can not.
Actually you are running a script. In Script, if the target directory does not exist, you will receive an error, like "Not a directory".
Ghostscript does not create directories, so no, it can't do that.
No, Ghostscript does not create new directories. It only creates new files. It can only write these files to existing directories.
It is the task of your script to prepare everything. Your script needs to create the new folder in advance where you want Ghostscript to write the output to.
I want to create temp files inside users 'My Documents' folder using php.
Is there any inbuilt function available in PHP?
Here is the answer.
<?php echo getenv("HOMEDRIVE") . getenv("HOMEPATH"); ?>
I'll just assume you're running PHP locally on the users PC...
You can get the user profile folder via the $_SERVER superglobal:
$_SERVER['USERPROFILE']
Appending Documents to this should point to the default path. Running the following at the command line:
php -r "echo $_SERVER['USERPROFILE'] . '\Documents';"
gives:
C:\users\<username>\Documents
Note: It's possible to move the location of the documents folder so this is not a bullet-proof method.
I am trying to delete photo in php using unlink. I have used it earlier on other server but this time it is not working. I have used absolute path for a test but still does not works:
I have used it as:
unlink('img1.jpg');
and :
unlink('http://www.mysite.com/img1.jpg');
Please anyone having such experience?
url not allow in ulink function
can you please used this
It's better, also safety wise to use an absolute path. But you can get this path dynamically.
E.g. using:
getcwd();
Depending on where your PHP script is, your variable could look like this:
$deleteImage = getcwd() . 'img1.jpg';
unlink($deleteImage);
check this
bool unlink ( string $filename [, resource $context ] )
and
filename
Path to the file.
So it only takes a string as filename.
Make sure the file is reachable with the path from the location you execute the script. This is not a problem with absolute paths, but you might have one with relative paths.
Even though unlink() supports URLs (see here) now, http:// is not supported: http wrapper information
use a filesystem path to delete the file.
If you use unlink in a linux or unix you should also check the results of is_writable ( string $filename )
And if the function returns false, you should check the file permissions with fileperms ( string $filename ).
File permissions are usual problems on webspaces, e.g. if you upload an file per ftp with a ftp user, and the webserver is running as an different user.
If this is the problem, you have do to a
chmod o+rwd img1.jpg
or
chmod 777 img1.jpg
to grand write (and delete) permissions for other Users.
unlink($fileName); failed for me.
Then I tried using the realpath($fileName) function as unlink(realpath($fileName)); it worked.
Just posting it, in case if any one finds it useful.
php unlink
use filesystem path,
first define path like this:
define("WEB_ROOT",substr(dirname(__FILE__),0,strlen(dirname(__FILE__))-3));
and check file is exist or not,if exist then unlink the file.
$filename=WEB_ROOT."img1.jpg";
if(file_exists($filename))
{
$img=unlink(WEB_ROOT."img1.jpg");
}
unlink won't work with unlink('http://www.mysite.com/img1.jpg');
use instead
unlink($_SERVER['DOCUMENT_ROOT'].'img1.jpg');//takes the current directory
or,
unlink($_SERVER['DOCUMENT_ROOT'].'dir_name/img1.jpg');
There may be file permission issue.please check for this.
Give relative path from the folder where images are kept to the file where you are writing script.
If file structure is like:
-your php file
-images
-1.jpg
then
unlink(images/1.jpg);
Or there may be some folder permission issue. Your files are on a server or you are running it on localhost? If it is on a server then give 755 permission to the images folder.
you are using url insted of path, here is how you should do it...
i am assuming your are uploading the picture to public_html. i suggest you to create a folder for pictures.
unlink("public_html/img1.jpg");