Jump to content


Photo

making files


  • Please log in to reply
13 replies to this topic

#1 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 15 October 2006 - 07:48 AM

how do you make a file in php. like mkdir, is there a function for making files...

#2 dymon

dymon
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 15 October 2006 - 07:57 AM

Such a function is touch().

Try this link: http://www.php.net/m...ction.touch.php
Web is the future ... desktop will die ...

#3 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 15 October 2006 - 12:50 PM

sure, touch will create a file if it doesnt exist, but its primary aim is to alter the date/time of a file.

what you want to look at is fopen which is for both opening existing and creating new files.
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#4 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 15 October 2006 - 05:31 PM

thanks, fopen works perfect.

#5 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 15 October 2006 - 05:34 PM

i have another problem. this could doesnt work anyone can help me??
<?php

	mkdir("$dir/modules/$_POST[title]", 0777);
	fopen("$dir/modules/$_POST[title]/index.php", 'w');
	$somecontent = "<?php
if (realpath(__FILE__) == realpath($_SERVER[SCRIPT_FILENAME])) {
header('Location: ../../index.php'); die(); }


	$query = $config->query("SELECT * FROM table_mod_page WHERE title = '$_GET[mod]'");
    $row = mysql_fetch_array($query);
    $data = $row[body];
    echo $data;
	?>";
	
	if (is_writable("$dir/modules/$_POST[title]/index.php")) {
	   if (!$handle = fopen("$dir/modules/$_POST[title]/index.php", 'a')) {
         echo "Cannot open file ($dir/modules/$_POST[title]/index.php)";
         exit;
   		}

   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($dir/modules/$_POST[title]/index.php)";
       exit;
  	 }
  
   echo "Success, wrote ($somecontent) to file ($dir/modules/$_POST[title]/index.php)";
  
   fclose($handle);

	} else {
  	 echo "The file $dir/modules/$_POST[title]/index.php is not writable";
	}
?>


#6 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 15 October 2006 - 06:05 PM

help1?!?!

#7 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 15 October 2006 - 07:00 PM

you'll need to be specific about what the script is/isnt doing. do you get errors? do you get anything output to the screen at all? as you're involving the database and the filesystem, each which can cause problems other than the PHP script alone, it's hard to tell just from looking at it...
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#8 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,015 posts

Posted 15 October 2006 - 07:18 PM

Take a look at the code you posted in reply #4 above and pay attention to the color coding. Strings should be red, php functions blue. So if the red spills onto the function calls you have a " or a ' missing somewhere to close a string literal.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#9 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 15 October 2006 - 07:50 PM

i dont get what ur saying someone help please not working.

#10 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,015 posts

Posted 15 October 2006 - 07:57 PM

[pre]

                  your string starts here
                  |
                  |
$somecontent = "<?php
if (realpath(__FILE__) == realpath($_SERVER[SCRIPT_FILENAME])) {
header('Location: ../../index.php'); die(); }


$query = $config->query("SELECT * FROM table_mod_page WHERE title = '$_GET[mod]'");
                          |
                          |
                          |
                          and finishes here !!!
[/pre]
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#11 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 15 October 2006 - 08:23 PM

on this line:

$query = $config->query("SELECT * FROM table_mod_page WHERE title = '$_GET[mod]'");
the first double quote is effectively closing the opening quote as pointed out by barand. if you want to enclose double quotes within double quotes, or single quotes within single quotes, you need to escape them. so the above line will become:

        $query = $config->query(\"SELECT * FROM table_mod_page WHERE title = '$_GET[mod]'\");
note the two backslashes \ i added.
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#12 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 15 October 2006 - 09:16 PM

OH OK THANK U SO MUCH REDBULL THATS ALL I NEEDED EVERYONE ELSE WASNT HELPING ME MUCH.

#13 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,015 posts

Posted 15 October 2006 - 10:29 PM

Sorry, Newb. I didn't realise you still needed to be spoon-fed.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#14 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 15 October 2006 - 10:37 PM

Sorry, Newb. I didn't realise you still needed to be spoon-fed.

;D ;D
no worries newb, however a tad unfair - i learnt many a thing from barand in the early days and the fact that he took the time to help (and actually gave you the solution, albeit in a different way) makes your comment a bit off. have a little more appreciation.
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users