martinjamesroberts Posted January 31, 2011 Share Posted January 31, 2011 Hello there, I'm very new to PHP and I need some help (please!) Basically I'm writing an actionscript application and I am using a php file to save an image to the server, the problem is I define a name in actionscript before I send the information to the php and it continuously saves over the same file.. Ideally I would like to attach the (jpg) image to an email, send the mail and delete the image ready for a new image to be created.. is this possible ? At least, I would like to add a +1 to each filename to stop the file being saved over continuously ! Thanks in advance for any help <?php $fileName = $_GET['filename']; $fp = fopen( $fileName, 'wb' ); fwrite( $fp, $GLOBALS['HTTP_RAW_POST_DATA'] ); fclose( $fp ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/226227-basic-question-saving-images/ Share on other sites More sharing options...
QuickOldCar Posted January 31, 2011 Share Posted January 31, 2011 If this helps I made an add a timestamp function Here's the demo and code for it. http://get.blogdns.com/add-timestamp.php Quote Link to comment https://forums.phpfreaks.com/topic/226227-basic-question-saving-images/#findComment-1167816 Share on other sites More sharing options...
martinjamesroberts Posted January 31, 2011 Author Share Posted January 31, 2011 Hi there, This looks fine, do I just copy it into a new PHP file and then #include into my original and use addTimeStamp after the filename ? How would I use this with my code.. I'm good on actionscript but not super hot on php ! Thanks for your response Quote Link to comment https://forums.phpfreaks.com/topic/226227-basic-question-saving-images/#findComment-1167825 Share on other sites More sharing options...
QuickOldCar Posted February 1, 2011 Share Posted February 1, 2011 you can paste the above where gonna use it in your code, or can create a new php file and include just this. <?php function addTimestamp($filename) { $character = "/"; $target_check = strrchr($filename,$character); if ($target_check[$character]) { $temp_filename1 = end(explode($target_check[$character],$filename)); $target = true; } else { $temp_filename1 = $filename; } $temp_filename = strtolower(trim($temp_filename1)); //$timestamp = time();//or uncheck and use time $timestamp = date('Y-m-d-H-i-s');//this one more readable if ($target) { $new_filename = str_replace($temp_filename1, "$timestamp-$temp_filename", $filename); } else { $new_filename = "$timestamp-$temp_filename"; } return $new_filename; } ?> then for usage just use something like this $some_file = addTimestamp($some_file); Quote Link to comment https://forums.phpfreaks.com/topic/226227-basic-question-saving-images/#findComment-1168113 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.