unkempt Posted March 26, 2008 Share Posted March 26, 2008 Ok so i am using flash with php the following works well if the unlink.php (below) resides in the "temporary" folder : In flash: [pre]path = "http://localhost/temporary/unlink.php?"; var file:String = "barth_t8.jpg"; del = new LoadVars(); del.delstr = file; del.sendAndLoad(path, del, "POST"); del.onLoad = function(){ tracer = "file removed - "+this.removed; }[/pre] In PHP: [pre]<?php $myFile=$_POST[delstr]; unlink($myFile); print "&removed=".$myFile; ?>[pre][/pre][/pre] So.... if i was to make my path - "http://localhost/unlink.php?"; (i.e. no temporary folder) how could i change this so flash tells the php which folder the file resides in and then delete it? Any help would be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/98035-newbie-unlink-question/ Share on other sites More sharing options...
wildteen88 Posted March 26, 2008 Share Posted March 26, 2008 To provide the directory over the url, it'll need to be like this: http://yoursiter.com/unlink.php?dir=path/to/file Then in php you'd do: if(isset($_GET['dir']) && isset($_POST['delstr'])) { $dir_path = $_SERVER['DOCUMENT_ROOT'] . '/' . $_GET['dir']; $file_path = $dir_path . '/' . $_POST['delstr']; if(is_dir($dir_path) && file_exists($file_path)) { unlink($file_path); } else { 'ERROR: File (' . $file_path . ') does not exist!'; } } else { die('Invalid data!'); } Quote Link to comment https://forums.phpfreaks.com/topic/98035-newbie-unlink-question/#findComment-501600 Share on other sites More sharing options...
unkempt Posted March 26, 2008 Author Share Posted March 26, 2008 Excellent - that seems to work nicely - thankyou Quote Link to comment https://forums.phpfreaks.com/topic/98035-newbie-unlink-question/#findComment-501607 Share on other sites More sharing options...
unkempt Posted March 26, 2008 Author Share Posted March 26, 2008 Sorry to be a pain , but is there a way to let flash know its done the job?? Again i apologise for my ignorance - i am new to php Quote Link to comment https://forums.phpfreaks.com/topic/98035-newbie-unlink-question/#findComment-501610 Share on other sites More sharing options...
wildteen88 Posted March 26, 2008 Share Posted March 26, 2008 Looking at the Flash manual for the sendAndLoad function Flash can receive data from the page. Change the following in the in unlink.php: if(is_dir($dir_path) && file_exists($file_path)) { unlink($file_path); } to: if(is_dir($dir_path) && file_exists($file_path)) { unlink($file_path); echo '&deleted=OK&'; } Then in your flash change this: del.onLoad = function(){ tracer = "file removed - "+this.removed; } to: del.onLoad = function() { if(this.deleted== 'OK') { tracer = "file removed'; } } Quote Link to comment https://forums.phpfreaks.com/topic/98035-newbie-unlink-question/#findComment-501614 Share on other sites More sharing options...
unkempt Posted March 26, 2008 Author Share Posted March 26, 2008 Thankyou very very much - you have made my life a lot easier than the workarounds i had in mind. Could you recommend any good starter books - i am fairly ok with actionscript but this php is doing my head in Quote Link to comment https://forums.phpfreaks.com/topic/98035-newbie-unlink-question/#findComment-501624 Share on other sites More sharing options...
wildteen88 Posted March 26, 2008 Share Posted March 26, 2008 Thankyou very very much - you have made my life a lot easier than the workarounds i had in mind. Could you recommend any good starter books - i am fairly ok with actionscript but this php is doing my head in I'm a complete novice at Flash and actionscript - rarely use it. PHP is a programming language, like all programming languages it takes time to grasp. Quote Link to comment https://forums.phpfreaks.com/topic/98035-newbie-unlink-question/#findComment-501626 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.