hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : [php] whats wrong with this code?
Reply

Forum Jump

[php] whats wrong with this code?

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 09-18-2004, 06:48 PM
kneuf kneuf is offline
Web Hosting Master
 
Join Date: Feb 2003
Location: Canada
Posts: 716

[php] whats wrong with this code?


arggg, this has been bugging my for a little while now. I have a script that is supposed to make a new file in a directory using PHP's FTP functions. I can login fine, but when it goes to 'put' the file into its place, it doesn't work. The directory structure looks something like this:
--------------
/home/test/vhosts/test_site.loc/
--------------
I have a 'templates' file (the file that is used when making the new file) which is located at:
--------------
/home/test/vhosts/test_site.loc/inc/templates/default.inc.php
--------------
here is the code:
PHP Code:
<?
//$filename = $_GET['file'];
$ftp_server "192.168.1.102";
$ftp_user 'username';
$ftp_pass 'password';

$file_name $_POST['file_name'];
$file_op $_GET['file_op'];
$template $_POST['template'];
$base_dir "vhosts/test_site.loc/";
$template_dir "inc/templates/";
$source_file $file_name;
$filename $template_dir $template;

if (!
$file_op) {

?>
<form action='?file_op=make_new' method='post'>
<table>
<tr><th>Filename:</th><td><input type='text' name='file_name' value='test.php' class='form_but'></td><td><input type='submit' value='Make' class='form_but'></td></tr>
<tr><th>Template:</th><td colspan='2' align='left'><select name='template' class='form_but'>
<option value='default.inc.php'>Admin PopUp
</select></td></tr>
</table>
</form>
<?
} elseif ($file_op == "make_new") {

// set up basic connection
$conn_id ftp_connect($ftp_server);

// login with username and password
$login_result ftp_login($conn_id$ftp_user$ftp_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
   die(
"FTP connection has failed !");
}

// try to change the directory to somedir
if (ftp_chdir($conn_id$base_dir)) {
 
// upload the file
$upload ftp_put($conn_id$filename$source_fileFTP_BINARY);

// check upload status
if (!$upload) { 
       echo 
"<p>FTP upload has failed! Could not upload $source_file from $filename</p>";
   } else {
       echo 
"<p>Uploaded $source_file to $ftp_server as $filename</p>";
   }
// try to chmod $file to 777
$chmod_cmd="CHMOD 0777 ".$filename

if (
ftp_site($conn_id$chmod_cmd)) {
 echo 
"<p>$file chmoded successfully to 777\n</p>";
} else {
 echo 
"<p>could not chmod $file\n</p>";
}


} else {
   echo 
"Couldn't change directory\n";
}

// close the connection
ftp_close($conn_id);

}
?>
I can login and everything, but I get this message (not very descriptive):
FTP upload has failed! Could not upload test.php from inc/templates/default.inc.php
-------------------
I know the code is a little messy, I am just trying to get it to work right now. Any ideas?
[edit]
and yes, the files(and directories) are chmod'd to 777)

__________________
www.kneuf.com
Proudly Canadian



Sponsored Links
  #2  
Old 09-19-2004, 05:35 PM
pphillips pphillips is offline
Web Hosting Master
 
Join Date: May 2003
Location: California, USA, Earth
Posts: 997
Add this into your form tag:

enctype="multipart/form-data"

EDIT: Actually you'd need that for uploading a new file through the form. Not sure about creating a new file via a form without uploading anything.

__________________
Blesta - Professional Billing Software
Innovation that benefits the user experience
Trial - Demo | 866.478.7567 | Twitter @blesta


Last edited by pphillips; 09-19-2004 at 05:39 PM.
  #3  
Old 09-19-2004, 06:03 PM
pphillips pphillips is offline
Web Hosting Master
 
Join Date: May 2003
Location: California, USA, Earth
Posts: 997
Are you trying to upload a filename specified in your form via this line?

$upload = ftp_put($conn_id, $filename, $source_file, FTP_BINARY);

Is $filename suppose to be the same as $file_name = $_POST['file_name']; ?

If so the variable names do not match, but I do not see how you can upload a variable to a file without creating the file first. Look into fopen. Also, not sure what you want to put into the file or where that comes from. Unless the file name in your form is a file that already exists on the server and your just uploading it to a remote site.

__________________
Blesta - Professional Billing Software
Innovation that benefits the user experience
Trial - Demo | 866.478.7567 | Twitter @blesta

Sponsored Links
  #4  
Old 09-19-2004, 09:40 PM
kneuf kneuf is offline
Web Hosting Master
 
Join Date: Feb 2003
Location: Canada
Posts: 716
No, I am not trying to upload a file. I have a 'template' file stored in another directory, that I am copying into a new location (the new file)... I know the variables are a little messed up but they are there. I can't use fopen because it doesn't allow me to chmod the file to what I need (safe_mode on), so I am using FTP to create the new file, and change the permissions. Also, I have done this before using the same concept and it worked flawlessy, however all the files were in the same directory as each other (the 'template' file and the new file), and I don't know why this isn't working.

__________________
www.kneuf.com
Proudly Canadian

  #5  
Old 09-28-2004, 03:08 PM
kneuf kneuf is offline
Web Hosting Master
 
Join Date: Feb 2003
Location: Canada
Posts: 716
OK, just an update. I got it to work, I re did it all and filled in the full path to the download file and full path to the new file and it works

__________________
www.kneuf.com
Proudly Canadian

Reply

Related posts from TheWhir.com
Title Type Date Posted
Web Host Code Spaces Closes Shop After Hacker Deletes Customer Data Web Hosting News 2014-06-19 16:34:41
Firebase Launches Hosting Service for Developers Web Hosting News 2014-05-14 15:52:13
Web Hosting Sales and Promos Roundup - May 2, 2014 Web Hosting News 2014-05-23 16:54:17
Free WHD.global Registration with the WHIR Coupon Code Blog 2014-01-30 13:24:20
cPanel Conference 2012: Branding and How to Do it Better with Felipe Gasper Web Hosting News 2012-10-09 18:00:02


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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 Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?