Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Old 12-15-2006, 01:45 PM   #1 (permalink)
Member
 
Join Date: 08-02-06
Posts: 39
iTrader: 0 / 0%
Latest Blog:
None

tosaha is liked by many
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
tosaha is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-15-2006, 02:59 PM   #2 (permalink)
Member
 
Join Date: 08-02-06
Posts: 39
iTrader: 0 / 0%
Latest Blog:
None

tosaha is liked by many
Never mind! I found the problem and I'm a complete idiot. I forgot to actually open the file. Correct code should be.

// 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_open, $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);
tosaha is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-15-2006, 03:20 PM   #3 (permalink)
v7n Mentor
 
Taltos's Avatar
 
Join Date: 11-22-06
Location: Phoenix, AZ
Posts: 1,784
iTrader: 0 / 0%
Latest Blog:
None

Taltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web pro
Good job solving your own problem and better job for posting your solution!!
__________________
Experimenting
Taltos is offline  
Add Post to del.icio.us
Reply With Quote
Old 12-18-2006, 01:15 PM   #4 (permalink)
v7n Mentor
 
Izzmo's Avatar
 
Join Date: 11-01-03
Location: Kansas City
Posts: 1,338
iTrader: 0 / 0%
Latest Blog:
Starting p90x today

Izzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web pro
Send a message via ICQ to Izzmo Send a message via AIM to Izzmo Send a message via MSN to Izzmo Send a message via Yahoo to Izzmo
++rep
__________________
Izzmo
Coding Guru Extraordinaire
ZeroWeb Hosting & Design - Customizable hosting for every type of user!
Izzmo is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with php error. will pay you CircleOfLinks Coding Forum 8 01-16-2007 01:35 PM
PHP Error Help Limit Coding Forum 21 12-22-2004 10:03 AM


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 05:37 PM.
© Copyright 2008 V7 Inc
Powered by vBulletin
Copyright © 2000-2009 Jelsoft Enterprises Limited.


Search Engine Optimization by vBSEO 3.3.0 ©2009, Crawlability, Inc.