Jump to content

Rename uploaded file with Order Number


121man

Recommended Posts

Hi,

I have made a custom form on the addresses page when checking out which allows file uploads by my customers, the php script and form work fine and files are uploaded just fine.

I would like a way of making it so the files uploaded are renamed or added the order number to when the order is placed so i can pin point which image was uploaded for which order.

So a file called Prestashop.jpg renamed to either Prestashop-22324.jpg or simply 22324.jpg where 22324 is the order number.

The code for the PHP file that processes the upload is as below I think it's right :-

include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');

if(intval(Configuration::get('PS_REWRITING_SETTINGS')) === 1)
   $rewrited_url = __PS_BASE_URI__;

include(dirname(__FILE__).'/header.php');
$smarty->display(_PS_THEME_DIR_.'uploadstatus.tpl');

// Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$front_Name = $_FILES['front']['name'];
@$front_Size = $_FILES['front']['size'];
@$front_Temp = $_FILES['front']['tmp_name'];
@$front_Mime_Type = $_FILES['front']['type'];
@$back2_Name = $_FILES['back2']['name'];
@$back2_Size = $_FILES['back2']['size'];
@$back2_Temp = $_FILES['back2']['tmp_name'];
@$back2_Mime_Type = $_FILES['back2']['type'];
@$order_name = $id_order;

function RecursiveMkdir($path)
{
  if (!file_exists($path)) 
  { 
     RecursiveMkdir(dirname($path));
     mkdir($path, 0777);
   }
 }


// Validation
if( $front_Size == 0)
{
die("
Please enter a valid front");
}
if( $front_Size >40960000000000)
{
//delete file 
unlink($front_Temp);
die("
Please enter a valid front");
}
if( $front_Mime_Type != "application/pdf" AND $front_Mime_Type != "image/pjpeg" AND $front_Mime_Type != "image/jpeg" AND $front_Mime_Type != "image/png" AND $front_Mime_Type != "image/prs.btif" AND $front_Mime_Type != "image/tiff" )
{
unlink($front_Temp);
die("
Please enter a valid front");
}
$uploadFile = "../artwork/"."4C".$order_name."-".$front_Name ;
if (!is_dir(dirname($uploadFile)))
 {
   @RecursiveMkdir(dirname($uploadFile)); 
 }
else
 {
 @chmod(dirname($uploadFile), 0777);
 }
@move_uploaded_file( $front_Temp , $uploadFile); 
$front_URL = "http://www.4colourprints.com/artwork/".$front_Name ;

if( $back2_Size == 0)
{
die("
Please enter a valid back2");
}
if( $back2_Size >40960000000000)
{
//delete file 
unlink($back2_Temp);
die("
Please enter a valid back2");
}
if( $back2_Mime_Type != "application/pdf" AND $back2_Mime_Type != "image/pjpeg" AND $back2_Mime_Type != "image/jpeg" AND $back2_Mime_Type != "image/png" AND $back2_Mime_Type != "image/prs.btif" AND $back2_Mime_Type != "image/prs.pti" AND $back2_Mime_Type != "image/tiff" )
{
unlink($back2_Temp);
die("
Please enter a valid back2");
}
$uploadFile = "../artwork/"."4C".$order_name."-".$back2_Name ;
if (!is_dir(dirname($uploadFile)))
 {
   @RecursiveMkdir(dirname($uploadFile)); 
 }
else
 {
 @chmod(dirname($uploadFile), 0777);
 }
@move_uploaded_file( $back2_Temp , $uploadFile); 
$back2_URL = "http://www.4colourprints.com/artwork/".$back2_Name ;

echo("
Submitted");

include(dirname(__FILE__).'/footer.php');



Any help is really appreciated

Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...