Jump to content

Probably an Idiot


arkum

Recommended Posts

Hello,

I'm pretty crap with php, and I think the answer to this must be very simple...

I've got a bit of code that works fine. Originally the value asigned to $myfilePath was passed in like so:

[code]$myFilePath=$_POST["pathToFile"];[/code]

And this worked fine. But now I have decided I want it hardcoded so I've tried this:

[code]$myFilePath="myfolder/";[/code]

But this causes the script to fail.

Here is the script with the rellevent bit in red:

[code]<?php
$tField=$_POST["myTextField"];
[color=red]$myFileName= $_POST["myFileName"];
$content=$_POST["myContent"];
$myFilePath="myFolder/"
$myFileFull = $myFilePath.$myFileName;[/color]
$targetFile;
$msg;

if(file_exists($myFileFull)) {
$msg = 'Exists';
if(is_writable($myFileFull)) {
$msg .= '_isWritable';
if (!$targetFile = fopen($myFileFull, 'w+')){
$msg .= "_can't be opened";
}else{
if(fwrite($targetFile, $content) === FALSE){
$msg .= "_can't be written";
}else{
$msg .= '_isWritten';
}
}
}else{
$msg .= '_is not writable';
}
}else{
$msg = "Doesn't Exist";
$timestamp = strtotime("now");
$myFileName = 'body_'. $timestamp;
$myFileFull = $myFilePath.$myFileName;
if (!$targetFile = fopen($myFileFull, 'w')){
$msg .= "_($myFileName)_Can't create NEW file";
}else{
if(fwrite($targetFile, $content) === FALSE){
$msg .= "_($myFileName)_Can't write to NEW file";
}else{
$msg .= '_($myFileName)_is CREATED and isWritten';
}
}
}

echo "&msg=$msg&myFile=$myFileName&content=$content&myTextField=$tField";

?> 
[/code]

Thanks
Link to comment
https://forums.phpfreaks.com/topic/34409-probably-an-idiot/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.