Current location: Hot Scripts Forums » Programming Languages » PHP » Cant create file


Cant create file

Reply
  #1 (permalink)  
Old 11-13-08, 07:24 AM
firestar firestar is offline
Newbie Coder
 
Join Date: Sep 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Cant create file

I have this problem. i use mkdir() to create a folder. after that, i use touch() to create a file but the file somehow cant be created. Why is it like this?
The folder has chmod 777, why cant i use touch to create a file in this
folder? how can i solve this problem in order to create the file?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-13-08, 12:52 PM
ianbrind ianbrind is offline
Wannabe Coder
 
Join Date: Jul 2008
Location: Somerset UK!
Posts: 192
Thanks: 0
Thanked 0 Times in 0 Posts
fopen(); instead of touch() maybe.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-13-08, 08:33 PM
firestar firestar is offline
Newbie Coder
 
Join Date: Sep 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
i still have problem in creating the file. what is the problem?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-13-08, 11:18 PM
mityelir88 mityelir88 is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
maybe you could show us the error message
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 11-14-08, 07:08 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Your probably forgetting to add a slash between the folder path and the file name.

Try it like this:
PHP Code:

<?php
$path
=dirname(__FILE__);
$slash=strpos($path,'/') ? '/' '\\';
define('BASE_DIR',$path.$slash);
$folder="myFolder";          // folder name
$dirPath=BASE_DIR.$folder;   // folder path
$file_name="myFile.txt";     // file name
if(@mkdir($dirPath,'0777'))
{
 
touch($dirPath.$slash.$file_name);
 echo 
"The folder and file was successfully created.<br /><b>".$dirPath.$slash.$file_name."</b><br />";
 }
else
{
 echo 
"There was a problem creating the folder or the file.<br />
       Either the folder already exists or you do not have permission to create the folder or file.<br /><b>"
.
       
$dirPath.$slash.$file_name."</b><br />";
 }
?>
__________________
Jerry Broughton

Last edited by job0107; 11-14-08 at 07:34 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hello all, can you help me? K4ot1K Other Languages 2 01-23-09 06:23 AM
Write to php file with php script or create new file, it is possible? Oskare100 PHP 10 08-14-08 10:03 AM
create php file on the fly and delete when session ends recedo PHP 0 01-06-06 11:28 PM
I need to create an Index. file LindaBellppo New Members & Introductions 1 09-05-05 05:34 PM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM


All times are GMT -5. The time now is 08:34 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.