Reply
Parameters - simple for someone - please help
Old 03-16-2006, 06:53 AM Parameters - simple for someone - please help
Junior Talker

Posts: 3
I have the attached script which works fine to delete a named file (in tis case 12.jpg) but i want that file name to be deleted to be specified in a form field in a browser. In other words the user enters the file name to be removed and submits the form and the script deletes that file. Any help would be apprciated.

<?php
// set up the settings
$file = 'public_html/admin/12.jpg';

$ftp_server = 'ftp.here.com';
$ftpuser = 'user';
$ftppass = 'abcd1234';

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

// login with username and password
$login_result = ftp_login($conn_id, $ftpuser, $ftppass);

// try to delete $file
if (ftp_delete($conn_id, $file)) { // the ftp function
echo "$file deleted successful\n";
} else {
echo "could not delete $file\n";
}

// close the connection
ftp_close($conn_id);

?>
froggy is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 03-16-2006, 07:54 AM Re: Parameters - simple for someone - please help
Novice Talker

Posts: 10
Hello,

Just add a basic HTML form, such as

Code:
<form action="" method="post">
Enter file name: <input type="text" name="file" /><br />
<input type="submit" name="submit" value="Delete file!" />
</form>
Then, run the PHP script with the submitted file parameter instead:

PHP Code:
<?
if(isset("submit")) {
 
// set up the settings 
$file 'public_html/admin/'.$_POST["file"]; 
 
$ftp_server 'ftp.here.com'
$ftpuser 'user'
$ftppass 'abcd1234'
 
// set up basic connection 
$conn_id ftp_connect($ftp_server); 
 
// login with username and password 
$login_result ftp_login($conn_id$ftpuser$ftppass); 
 
// try to delete $file 
if (ftp_delete($conn_id$file)) { // the ftp function 
echo "$file deleted successful\n"
} else { 
echo 
"could not delete $file\n"

 
// close the connection 
ftp_close($conn_id);
 
}
?>

Let me know if you can't get it to work!

- Sindre
__________________
Magento Optimized Web Hosting
Premium hosting services for the Magento eCommerce platform.
Professional Magento Installation included with every plan.
Sindre is offline
Reply With Quote
View Public Profile Visit Sindre's homepage!
 
Old 03-16-2006, 11:48 AM Re: Parameters - simple for someone - please help
Junior Talker

Posts: 3
Thanks for your help but I get the following error report when the page loads:

Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /home/micha15431/public_html/admin/delete_script.php on line 78

Line 78 being:

if(isset("submit")) {

Any ideas?

Froggy
froggy is offline
Reply With Quote
View Public Profile
 
Old 03-16-2006, 12:06 PM Re: Parameters - simple for someone - please help
Extreme Talker

Posts: 219
Location: UK, East Anglia
Change it to :

PHP Code:
if(isset($submit)) { 
timsquash5 is offline
Reply With Quote
View Public Profile
 
Old 03-16-2006, 12:14 PM Re: Parameters - simple for someone - please help
Junior Talker

Posts: 3
Superb - Thanks Sindre - a great help.
froggy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Parameters - simple for someone - please help
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13188 seconds with 12 queries