Menu

have process.php name upload &overwrite old 1

Help
chris h
2008-04-22
2013-06-03
  • chris h

    chris h - 2008-04-22

    hey guys,

    this one might be simple but i know very limited php commands.

    i want to use the formgen to have my clients upload their header image and replace their existing image, since the process.php names it upon upload i figured i could modify it to name the upload  

    companyname.gif  

    and overwrite the existing companyname.gif  in the folder
    (not sure if the overwrite needs to be added as a php fuction also?)

    here is the process.php i am using at the moment

    i think all i ahev to do is modify this line: "files/".$image_part);
    ...but im not sure, figured i'd get some advice before i break something :)

    thanks in advance

    <?php
    include("global.inc.php");
    $errors=0;
    $error="The following errors occured while processing your form input.<ul>";
    $Image=$HTTP_POST_FILES['Image'];
    if($Image=="" ){
    $errors=1;
    $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
    }
    if(!is_uploaded_file($HTTP_POST_FILES['Image']['tmp_name'])){
    $error.="<li>The file, ".$HTTP_POST_FILES['Image']['name'].", was not uploaded!";
    $errors=1;
    }
    if($errors==1) echo $error;
    else{
    $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Image']['name'];
    $image_list[0] = $image_part;
    copy($HTTP_POST_FILES['Image']['tmp_name'], "files/".$image_part);
    $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
    $message="Image: ".$where_form_is."files/".$image_list[0]."
    ";
    $message = stripslashes($message);
    mail("$email","Form Submitted at your website",$message,"From: phpFormGenerator");
    $make=fopen("admin/data.dat","a");
    $to_put="";
    $to_put .= $where_form_is."files/".$image_list[0]."
    ";
    fwrite($make,$to_put);

    header("Refresh: 0;url=$redirect");
    ?><?php
    }
    ?>

     
    • TNTEverett

      TNTEverett - 2008-04-22

      You may want to have some level of backup by keeping the date/time coded filename and make a copy with the name you want. 

      Add this line right after the one copying the date/time coded file name. 
      copy($HTTP_POST_FILES['Image']['tmp_name'], "files/".$nameyouwant);

      Then change this line
      $message="Image: ".$where_form_is."files/".$image_list[0]."
      ";

      to

      $message="Image: ".$where_form_is."files/".$image_list[0]." as ".$nameyouwant."
      ";

      This way you can keep record of the original date/time coded name verses the "nameyouwant".

       
    • chris h

      chris h - 2008-04-22

      thanks TNT, you helped me out last time i was on here

      i almost got it to work but it just calls the item "gif" instead of "header.gif"

      the process.php must be reading the . between the header and gif?

      i tried removing the .gif form the script and it stopped creating a new file all together

      here is what i got

      <?php
      include("global.inc.php");
      $errors=0;
      $error="The following errors occured while processing your form input.<ul>";
      $Image=$HTTP_POST_FILES['Image'];
      if($Image=="" ){
      $errors=1;
      $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
      }
      if(!is_uploaded_file($HTTP_POST_FILES['Image']['tmp_name'])){
      $error.="<li>The file, ".$HTTP_POST_FILES['Image']['name'].", was not uploaded!";
      $errors=1;
      }
      if($errors==1) echo $error;
      else{
      $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Image']['name'];
      $image_list[0] = $image_part;
      copy($HTTP_POST_FILES['Image']['tmp_name'], "files/".$image_part);
      copy($HTTP_POST_FILES['Image']['tmp_name'], "files/".$header.gif);
      $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
      $message="Image: ".$where_form_is."files/".$image_list[0]." as ".$header.gif."
      ";
      $message = stripslashes($message);
      mail("$email","Form Submitted at your website",$message,"From: phpFormGenerator");
      $make=fopen("admin/data.dat","a");
      $to_put="";
      $to_put .= $where_form_is."files/".$image_list[0]."
      ";
      fwrite($make,$to_put);

      header("Refresh: 0;url=$redirect");
      ?><?php
      }
      ?>

      thanks

       
      • TNTEverett

        TNTEverett - 2008-04-25

        1.) $header is never defined so it will always return blank.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.