Get 'My Documents' path in windows using php - php

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.

Related

i try creat folder using php script as well in pvs server that system ubuntu

<?php
$type="student";
$paths="klm";
$a2="med";
$da="_";
$a23=$type.$da.$paths.$da.$a2;
$enpath=$type.'//'.$a23;
$folder_name=$enpath;
if (!file_exists($output_dir . $folder_name))
{
#mkdir($output_dir . $folder_name, 0777,true);
echo "Folder Created";
}
?>
xhello dev linux please fix my problem
im using script php in server vps trying to creat folders look like this screen but when i search about those folders i cant find it
the file.php in folder that this path: home/public/file.php
and also in this path there student folder : home/public/student
so i need to make child folder in student folder
Your code is a bit tricky but looks like $output_dir is undefined so is null due to PHP default behavior. So you're trying to create student/student_klm_med dir, not a /home/public/student/student_klm_med or whatever. Note that mkdir() requires an absolute system path to create a directory.

Laravel storage_path for shell script

I have a Laravel app that needs to run a shell script, to do so I'm using exec(). The shell script creates a file that I want to store in my storage folder, however the shell script requires the path for the storage folder.
If I use storage_path() it returns something like "/home/vagrant/project/storage" which works fine when it comes to referencing things within my web app, but as far as the shell script is concerned isn't correct.
The correct path on homestead would be: ~/project/storage and on live/staging it would be something like /var/www/project/storage.
Is there a elegant way of Laravel acquiring the exact path to pass to the shell script or am I going to have to specify it in my .env file and use that instead?
Default value returned by storage_path() always points to storage/ folder in your project's root. Regardless in which folder you put your project application, value returned by the helper will be correct.
If you want to change the default value of storage_path, you can do so with App::useStoragePath($path). If this value should be different for different environments you need to read the path from .env file - that's what it is for.
App::useStoragePath(env('STORAGE_PATH'));

How do you find the php file a function is defined in in wordpress?

I'm a newbie at WordPress PHP.
I'm looking in the header.php file and it's calling:
<?php suffusion_before_page(); ?>
For this function and any other function in WordPress/PHP how do I find which file that function is being defined?
If you have SSH access to the server you can use grep to find the function definition.
grep -R 'function suffusion_before_page' /path/to/theme
If you don't you can download the theme files and search for it using a program of your choice. Notepad++ has a find in files feature.
If you are using Windows OS, then you can use GrepWin. Check the screenshots how to use this:
Selecting folder to search by grepwin:
Using search string in the textbox to search:
Grepwin Download Link
Look in your hosting cPanel site under your site directory with the rest of your files for your site. The file name is suffusion_before_page.php, which is what you should look for.
You can try and go to www.yoursite.com/wp-admin/theme-editor.php, and then control + f to bring up the search function in browser. Type in "suffusion_before_page.php", then click that file and you can see it.
If you use Windows you can enter something like this to command prompt:
find /c /i "function suffusion_before_page(" C:\path\to\wordpress\folder\*.* | find ": 0" /v
Change the path, of course.

PHP/ImageMagick/Ghostcript: change output + input file paths

I have Ghostscript installed and ImageMagick (DLL).
The following PHP code works fine:
exec("convert test_pdf.pdf[0] $value.jpg");
But I want to read the PDF input from a different path (not from the location of PHP page).
I also want to write the output to a different path.
How do I do that?
You can create a variable for the different path and add it to your exec command:
<?php
$path = "/path/to/file/";
exec('convert '.$path.'test_pdf.pdf[0] '.$path.$value.'.jpg');
?>
You'll need to also make sure you have permissions set correctly for the new path in order to read/write from it using the exec command.

Using php oncli few questions ~ using XAMPP

Attempting to expand my knowledge by using PHP on the Command Line.
Currently I have a default installation of XAMPP, and have set up my Environment Variable.
I've been able to execute simple scripts like:
<?php echo 'hello world!'; ?>
Questions ~
Where do I store the scripts I am using? Currently I am doing:
C:\Users\Ross>php c:\helloworld.php
it works. Does this mean I need to specify a path every time? Or should I store php files inside my c:>xampp\php directory? I tried this and it doesn't appear to work.
What would be the accepted "best practice".
2nd question
Could someone explain why this doesn't work:
<?php
fwrite(STDOUT, "Enter file name:\n");
$file=fgets(STDIN);
print 'you entered...' . $file;
$fp=fopen($file,'r');
if(!$fp)
{
print 'File could not be opened..';
}
else
{
/* show file pointer */
print($fp);
}
?>
and then I do:
C:\Users\Ross>php c:\file.php
Enter file name:
c:\foo.txt
you entered...c:\foo.txt
Warning: fopen(c:\foo.txt): failed to open stream: Invalid argument in C:\file.php on line 6
File could not be opened..
"foo.txt" is in the same directory and does exist.
thanks for any clarification.
As far as were to store the files is concerned: I normally add the directory where php.exe is to my PATH environment variable, that way I can just call php in whatever directory contains the script I need to run. If you don't add the directory to PATH, then you would need to either run php from its directory and specify the full path to the PHP script, or run it from the directory where the PHP script is and specify the full path to the PHP executable.
Regarding opening the file: the reason this is occurring is because fgets is returning the newline from you pressing enter, too (it would seem). So in reality, it's trying to open a file whose name actually ends with a new line character.
Change the line:
$file=fgets(STDIN);
to:
$file=trim(fgets(STDIN));
and you should be fine.
question #1: all your php files should be inside the www folder of xampp (c:\xampp\www)
question #2: probably because you are not working in the correct folder.
xammp is good but I recommend you to use wamp, it's much easier to understand and use. Just google for it. xampp is more for those who are more techically skilled.

Categories