|
PHP fwrite() error.
Hello all, I was hoping I could get some help with this. I've written this piece of php code:
<?php
// Setting form variables.
$kmp_fname = $_POST["kmp_fname"];
$kmp_lname = $_POST["kmp_lname"];
$kmp_nname = $_POST["kmp_nname"];
$kmp_password = $_POST["kmp_password"];
$kmp_cpassword = $_POST["kmp_cpassword"];
$kmp_email = $_POST["kmp_email"];
$kmp_cemail = $_POST["kmp_cemail"];
$kmp_fupload = $_POST["kmp_fupload"];
$kmp_link = $_POST["kmp_link"];
$kmp_tac = $_POST["kmp_tac"];
// Where the file is going to be placed and define prefix.
$target_path = "spgm/gal/testgal/";
$prefix = "_thb_";
// Moved uploaded file to temporary folder /gal.
if(move_uploaded_file($_FILES['kmp_fupload']['tmp_name'], $target_path . $_FILES['kmp_fupload']['name'])) {
echo "<br />File " . $_FILES['kmp_fupload']['name'] . " has been moved to " . $target_path . " .<br />";
}
else {
echo "<br />Could not move " . $_FILES['kmp_fupload']['name'] . " to " . $target_path . " .<br />";
}
// Copy orignal file to the proper gallery.
$string_source = $target_path . basename( $_FILES['kmp_fupload']['name']);
$string_destination = $target_path . $prefix . basename( $_FILES['kmp_fupload']['name']);
if(copy ($string_source, $string_destination)) {
echo "<br />File " . $string_source . " has been copied to " . $string_destination . " .<br />";
}
else {
echo "<br />Could not copy " . $string_source . " to " . $string_destination . " .<br />";
}
// Adds link to the caption file pic-desc.txt.
$caption_file_path = $target_path . "pic-desc.txt";
$caption_file_open = fopen($caption_file_path, 'a+');
$new_caption_text = $prefix . basename( $_FILES['kmp_fupload']['name']) . " | <a href='http://" . $kmp_link . "' /></a>\n";
if(fwrite($caption_file_path, $new_caption_text)) {
echo "<br />'" . $new_caption_text . "' has been added to " . $caption_file_path . " .";
}
else {
echo "<br />Could not add '" . $new_caption_text . "' to " . $caption_file_path . " .";
}
fclose($caption_file_open);
?>
But whenever I run it I get the following results:
File sp_tom.bmp has been moved to spgm/gal/testgal/ .
File spgm/gal/testgal/sp_tom.bmp has been copied to spgm/gal/testgal/_thb_sp_tom.bmp .
Warning: fwrite(): supplied argument is not a valid stream resource in /webroot/h/a/hartm005/www/kmp_2_1_submitform.php on line 41
Could not add '_thb_sp_tom.bmp | ' to spgm/gal/testgal/pic-desc.txt .
I've gone through it with a fine tough comb, I've re-written it from scratch, I've searched the web for similar problems but I just can't seem to solve it.
Does anyone know why it isn't working? Any help would be appreciated.
Running PHP 4.4.x
Memory Limit: 48M
Maximum Execution Time: 120
Maximum Upload Filesize: 16M
Tosaha
|