473,378 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Question about File Creation

So I would like it so that a user can input something into a textbox, type a name for the file, and the file is saved in a subdirectory marked content. For example, if I picked the name of the file to be test.txt, I want the file to be saved in content/test.txt. I can't figure out how to save the file in that directory without putting the script in that directory.

What I have:
[PHP]$filename = $_POST['title'];
$text = $_POST['content'];

$fp = fopen ($filename, "w");
if ($fp) {
fwrite ($fp, $text);
fclose ($fp);
echo ("Content Added.");
}
else {
echo ("Error.");
}[/PHP]
Jul 30 '08 #1
2 974
Why not add the path to the filename? suppose the directory is /var/www/upload/content, you can add the path when creating the file.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $filename = '/var/www/upload/content/' . $_POST['title'];
  3. $fp = fopen ($filename, "w");
  4.  
  5. /* ...the rest of your code... */
  6.  
  7. ?>
  8.  
Jul 30 '08 #2
Atli
5,058 Expert 4TB
You should also be able to use a relative path.
Meaning that if your script is in /var/www/html/ and you want your content in
/var/www/html/content/, you could simply prefix your file name with content/.
Jul 31 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: SK | last post by:
I have a file. i get the creation time using File.GetCreationTime. then i go and delete that file. and then create it again and print the File.GetCreationTime. It is giving me the old creation...
2
by: David Fickbohm | last post by:
People, I am trying to determine the creation date of files in a folder. I am using the following code to find the folder and confirm that files exist in the folder. If someone could give me an...
2
by: Robizzle | last post by:
Sorry, I must be blind but I can't seem to find it anywhere. What function will return the time a file was created? I see filemtime(...) returns the time that file was last Modified and...
7
by: Marius III | last post by:
Hi there, I want to get the file version of a file in PHP. Do somebody have the code for this? Thanks alot!
7
by: Becci | last post by:
Is there a way to know, when we get an "ONChanged" event from the filesystemwatcher, what actually changed, file, last access, last write, etc? Seems they are all bundled into the one event?
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
8
by: Eddie Suey | last post by:
I want to add a new line to the begining of a text file. I dont want to write over existing data. How do I do this? the file is about 7 mb.
2
by: Al Reid | last post by:
I have been asked to write a program to monitor a certain directory structure and to copy all files created there to optical media for archival storage. It seems that it would be simple to...
8
by: Steven Scaife | last post by:
Hello I am creating a reporting system using SQL Server 2000 and ASP, I have created 4 pages that display the results i want, however the reports take an average of 20 mins to run and i have...
3
by: Brian | last post by:
A quick question here - What can be achieved in IL which is not possible in C# ? o Creation of an ArrayList o Creation of a Dictionary o Creation of a two dimensional array...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.