View Full Version : Basic problem
MrPinkPanther
03-04-2009, 06:58 PM
<?php
$title = $_POST["title"];
$content = $_POST["content"];
if(is_dir($title)) {
echo 'Already exists.';
} else {
mkdir($title);
$makeTextFile = fopen("$title/$title.txt" , "w");
$writeTextFile = fwrite($makeTextFile, $content);
fclose($makeTextFile);
echo 'All done';
}
?>
What (if anything) is wrong with this? It may be the app thats sending to it thats wrong but Im not 100% sure.
Excellent1
03-04-2009, 07:17 PM
What (if anything) is wrong with this? It may be the app thats sending to it thats wrong but Im not 100% sure.Are you getting any errors?
MrPinkPanther
03-04-2009, 07:43 PM
It creates the folder and text file inside it like it should but it doesnt write the content in the text file.
Dentafrice
03-04-2009, 08:03 PM
Well first off the code is awful, second off.. I'm pretty sure it's not posting the data, and is probably using a GET request.
How is your application sending the data? Is it through the URL? blah.php?type=test&name=blah
MrPinkPanther
03-04-2009, 08:12 PM
I'm sending it via POST from an xcode app like this:
"NSString *myRequestString = @"title=random title";"
If you dont mind me asking. How do you think I could sort out the PHP code?
Read your messages too :P
Dentafrice
03-04-2009, 08:19 PM
I'm sending it via POST from an xcode app like this:
"NSString *myRequestString = @"title=random title";"
If you dont mind me asking. How do you think I could sort out the PHP code?
Read your messages too :P
I read the message and replied to your thread.
<?php
/* Gets the data from the request. */
$title = $_POST["title"];
$content = $_POST["content"];
/* Checks for empty data. */
if(empty($title) || empty($content)) {
exit("You have empty fields.");
}
/* Checks to see if the folder exists. */
if(file_exists($title)) {
exit("Folder already exists.");
}
mkdir($title); // makes directory.
$file = file_put_contents("{$title}/{$title}.txt", $content); // puts the content in the file, saves it.
echo "All done.";
?>
MrPinkPanther
03-04-2009, 08:24 PM
You are a genious and I love you Ha ha.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.