Create dummy index.html inside a new MKDR directory - mkdir

I know this may be a silly question but i cant seem to find just a simple answer.
I have a php script that makes a directory for me when the user starts a new entry.
That directory holds photos for their gallery.
What i would like to do is also create One index.html file inside that new directory with a few lines of html code in it.
How do i do this?
Im guessing that the file would be made like so:
mkdir('users/'.$id.'/index.html',0755);
But how do i add the html into that index.html file?
Or do i have one file on the server and copy it over into there during the MKDIR process?
Anyways a really simple answer would be best as i am very slow in this learning thing.
Thank you
John
New edits.....
<?php
$id = 812;
mkdir('users/'.$id,0755);
chmod('users/'.$id,0777);
$fh = fopen( "users/".$id, "w+" ) or die( "Couldn't open file" );
fwrite( $fh, "<html><head /><body><h1>It Works!</h1></html>" );
fclose( $fh );
?>
Its giving me this error?
Warning: fopen(users/812) [function.fopen]: failed to open stream: Permission denied in stackoverflowtest1.php on line 9
Couldn't open file
Any ideas? I am on a wamp windows 7 server and not using ftp to edit files but just the www wamp explorer foler.

I'm not sure which language you are using so you'll either need to update your question or forgive the lack of concrete code. mkdir is for generating directories and not flat files. To do that you'll need to open then the file handle then print the HTML lines to that handle and then close it.
A file handle is a pointer to a file. It allows you to manipulate the data in that file ( i.e. read or write it ).
example code:
$fh = fopen( "path/to/file/index.html", "w+" ) or die( "Couldn't open file" );
fwrite( $fh, "<html><head /><body><h1>It Works!</h1></html>" );
fclose( $fh );
The path to the file needs a file name as a target, sorry that wasn't clear.

Related

While loop files in folder

I'm relatively new to Netlogo and already struggling ;)
I have the following problem: I want my program to open a folder, check a file in that folder and afterwards remove that file from that folder. I figured the best way to do this is via a while loop, but I'm struggling to find the right syntax. Hope you all can help!
The command 'file-open' will open a file using the path provided (the string after file-open: e.g. file-open "C:\Documents\model-out.txt" will open a file titled model-out.txt in the Documents folder on the C drive.)
You can then use 'file-read' or 'file-write' to read or write to the file respectively.
The command 'file-close' will close the file, which then can be deleted with 'file-delete'.
You can also check if a file exists in a folder using the command if file-exists? "C:\Documents\model-out.txt", and if true, the file can be deleted using file-delete.
Also check the command 'set-current-directory'.
Best,

How to access pdf file outside of public_html in joomla site?

Actually i want to edit a module to fetch PDF file outside from public_html.
I already tried to change permission of that file from which i want to fetch PDF to 777.
I am trying to fetch PDF by following codes
$baseurl = JURI::base();
$outside_baseurl = $baseurl.'../pdf/name.pdf';
Shows this error
Cannot access file!
https://mysitedomain.com/../pdf/name.pdf
It's really not safe to access a file outside the scope of your public folder in the open like that. It has the potential to open serious security holes. If you are trying to do this to modify or use the PDF file for something inside PHP, you should be able to. If you are trying to send it to a user for download or preview, you might wanna try fpassthru(). Something like the example below.
<?php
$path = 'path/to/file.pdf';
$public_name = basename($path);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $path);
header("Content-Disposition: attachment; filename=$public_name;");
header("Content-Type: $mime_type");
header('Content-Length: ' . filesize($path));
$fop = fopen($path, 'rb');
fpassthru($fop);
exit;
This should serve your purpose.

How to read a Bunch of files in a directory in lua

I have a path (as a string) to a directory. In that directory, are a bunch of text files. I want to go to that directory open it, and go to each text file and read the data.
I've tried
f = io.open(path)
f:read("*a")
I get the error "nil Is a directory"
I've tried:
f = io.popen(path)
I get the error: "Permission denied"
Is it just me, but it seems to be a lot harder than it should be to do basic file io in lua?
A directory isn't a file. You can't just open it.
And yes, lua itself has (intentionally) limited functionality.
You can use luafilesystem or luaposix and similar modules to get more features in this area.
You can also use the following script to list the names of the files in a given directory (assuming Unix/Posix):
dirname = '.'
f = io.popen('ls ' .. dirname)
for name in f:lines() do print(name) end

Pipe Console App to file from batch file

I have a console app (Visual Studio - VB), it runs, it does it's job.
I also have a batch file that runs the program and everything, but I want the output of my console app to also send to a text file.
This is my current batch, which creates the text file, but nothing is in it.
Start "" "C:\Users\wrossi\Desktop\NetLogOnSysInfo Solution\NetLogOnSysInfo Project\bin\Debug\NetLogOnSysInfo Project.exe" -all >>%ComputerName%.txt
Exit
Not sure if the batch is wrong, or if I should look at my program. Also, how do I define a path so I can put the output file exactly where I want it?
"C:\Users\wrossi\Desktop\
NetLogOnSysInfo Solution\NetLogOnSysInfo Project\bin\Debug\NetLogOnSysInfo Project.exe"
-all > %ComputerName%.txt
No need to use Start.
You are pretty close to what I think you want to do:
c:\console.exe > c:\output.exe
c:\console.exe or wherever the location of your console app > redirect stdout (use >> to append) c:\output.txt or wherever you want to create the text file.
Hope this helped.
Also just in case:
type stdin.txt | console.exe > stdout.txt
In the above example you can redirect an input from stdin.txt and pipe it into console.exe then redirect the output of console.exe to stdout.txt
I found one code recently after searching alot
if u wanna run .bat file in vb or c# or simply
just add this in the same manner in which i have written
here is the code
code > C:\Users\Lenovo\Desktop\output.txt
just replace word "code" with your .bat file code or command and after that the directory of output file

How do i read and write from/to a file in another directory?

I am trying to make a program that will write data to a file for another program to be able to read the data from it. The problem is that I can't figure out a way to do this when the file i am reading and writing from is in another directory than both of my programs. I know there are other ways of doing this, but I just thought that it would be useful to know how to do it. Anyone that can help me?
You can use the full path, e.g
local f1 = io.open('D:/test/b.txt') -- Windows
local f2 = io.open('/test/b.txt') -- Unix
or use relative path, e.g
local f = io.open('../../test/b.txt')
In this example, the file is in the test directory of the parent directory (..) of parent directory.