Jump to content

Recommended Posts

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 );
  
?>

Link to comment
https://forums.phpfreaks.com/topic/226227-basic-question-saving-images/
Share on other sites

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

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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.