Page 1 of 4 123 ... LastLast
Results 1 to 10 of 35
  1. #1
    Join Date
    Feb 2008
    Posts
    1,336
    Plugin Contributions
    1

    Default Allow Customers To Upload Images Using Contact Us Page?

    I have been trying to use a script to all my customers to upload images of their cars after they install the items. I found a few free php scripts that seem to work fine if used outside Zen Cart, the problem though is, if a customer upload an image there is no way for store owner to find out since it doesn't send an email to the store owner.
    The code require that you create an images directory in the same folder you install the file.
    Here is the complete php code
    PHP Code:
    <?php
    //define a maxim size for the uploaded images in Kb
     
    define ("MAX_SIZE","500"); 

    //This function reads the extension of the file. It is used to determine if the file  is an image by checking the extension.
     
    function getExtension($str) {
             
    $i strrpos($str,".");
             if (!
    $i) { return ""; }
             
    $l strlen($str) - $i;
             
    $ext substr($str,$i+1,$l);
             return 
    $ext;
     }

    //This variable is used as a flag. The value is initialized with 0 (meaning no error  found)  
    //and it will be changed to 1 if an errro occures.  
    //If the error occures the file will not be uploaded.
     
    $errors=0;
    //checks if the form has been submitted
     
    if(isset($_POST['Submit'])) 
     {
         
    //reads the name of the file the user submitted for uploading
         
    $image=$_FILES['image']['name'];
         
    //if it is not empty
         
    if ($image
         {
         
    //get the original name of the file from the clients machine
             
    $filename stripslashes($_FILES['image']['name']);
         
    //get the extension of the file in a lower case format
              
    $extension getExtension($filename);
             
    $extension strtolower($extension);
         
    //if it is not a known extension, we will suppose it is an error and will not  upload the file,  
        //otherwise we will do more tests
     
    if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
             {
            
    //print error message
                 
    echo '<h1>Unknown extension!</h1>';
                 
    $errors=1;
             }
             else
             {
    //get the size of the image in bytes
     //$_FILES['image']['tmp_name'] is the temporary filename of the file
     //in which the uploaded file was stored on the server
     
    $size=filesize($_FILES['image']['tmp_name']);

    //compare the size with the maxim size we defined and print error if bigger
    if ($size MAX_SIZE*1024)
    {
        echo 
    '<h1>You have exceeded the size limit!</h1>';
        
    $errors=1;
    }

    //we will give an unique name, for example the time in unix time format
    $image_name=time().'.'.$extension;
    //the new name will be containing the full path where will be stored (images folder)
    $newname="images/".$image_name;
    //we verify if the image has been uploaded, and print error instead
    $copied copy($_FILES['image']['tmp_name'], $newname);
    if (!
    $copied
    {
        echo 
    '<h1>Copy unsuccessfull!</h1>';
        
    $errors=1;
    }}}}

    //If no errors registred, print the success message
     
    if(isset($_POST['Submit']) && !$errors
     {
         echo 
    "<h1>File Uploaded Successfully! Try again!</h1>";
     }

     
    ?>

     <!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" -->
     <form name="newad" method="post" enctype="multipart/form-data"  action="">
     <table>
         <tr><td><input type="file" name="image"></td></tr>
         <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
     </table>    
     </form>
    I tried to edit the zen cart files so I can use this code. I edited the include/modules/pages/contact_us/header.php I added the following code from the above code:
    PHP Code:
    //define a maxim size for the uploaded images in Kb
     
    define ("MAX_SIZE","500"); 

    //This function reads the extension of the file. It is used to determine if the file  is an image by checking the extension.
     
    function getExtension($str) {
             
    $i strrpos($str,".");
             if (!
    $i) { return ""; }
             
    $l strlen($str) - $i;
             
    $ext substr($str,$i+1,$l);
             return 
    $ext;
     }

    //This variable is used as a flag. The value is initialized with 0 (meaning no error  found)  
    //and it will be changed to 1 if an errro occures.  
    //If the error occures the file will not be uploaded.
     
    $errors=0;
    //checks if the form has been submitted
     
    if(isset($_POST['Submit'])) 
     {
         
    //reads the name of the file the user submitted for uploading
         
    $image=$_FILES['image']['name'];
         
    //if it is not empty
         
    if ($image
         {
         
    //get the original name of the file from the clients machine
             
    $filename stripslashes($_FILES['image']['name']);
         
    //get the extension of the file in a lower case format
              
    $extension getExtension($filename);
             
    $extension strtolower($extension);
         
    //if it is not a known extension, we will suppose it is an error and will not  upload the file,  
        //otherwise we will do more tests
     
    if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
             {
            
    //print error message
                 
    echo '<h1>Unknown extension!</h1>';
                 
    $errors=1;
             }
             else
             {
    //get the size of the image in bytes
     //$_FILES['image']['tmp_name'] is the temporary filename of the file
     //in which the uploaded file was stored on the server
     
    $size=filesize($_FILES['image']['tmp_name']);

    //compare the size with the maxim size we defined and print error if bigger
    if ($size MAX_SIZE*1024)
    {
        echo 
    '<h1>You have exceeded the size limit!</h1>';
        
    $errors=1;
    }

    //we will give an unique name, for example the time in unix time format
    $image_name=time().'.'.$extension;
    //the new name will be containing the full path where will be stored (images folder)
    $newname="images/".$image_name;
    //we verify if the image has been uploaded, and print error instead
    $copied copy($_FILES['image']['tmp_name'], $newname);
    if (!
    $copied
    {
        echo 
    '<h1>Copy unsuccessfull!</h1>';
        
    $errors=1;
    }}}}

    //If no errors registred, print the success message
     
    if(isset($_POST['Submit']) && !$errors
     {
         echo 
    "<h1>File Uploaded Successfully! Try again!</h1>";
     } 
    Then added the html part of the code to includes/template/my_template/templates/tpl_contact_us_default.php
    PHP Code:
     <table>
         <
    tr><td><input type="file" name="image"></td></tr>
         <
    tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
     </
    table
    I created an images directory in the modules/pages/contact_us but for some reason when I tried to run the script I get the congratulation message but no images in the images folder. Also Is it possible to make the Send button in Zen Cart works as the Upload Image button?

  2. #2
    Join Date
    Feb 2008
    Posts
    1,336
    Plugin Contributions
    1

    Default Re: Allow Customers To Upload Images Using Contact Us Page

    Another question is, If I create a new page, and use Iframe to display the upload images form inside it, Can I add the function to send an email to the store owner once the customer upload an image?

  3. #3
    Join Date
    Feb 2008
    Posts
    1,336
    Plugin Contributions
    1

    Default Re: Allow Customers To Upload Images Using Contact Us Page

    I have managed to include an email form with the upload image form. Now if a customer upload an image to my website I get an email with all the customer information and the image is posted on my server. You can see it in action here: http://www.ohiospeedshop.com/gallery-c-298.html if anyone has a feedback or suggestion please let me know.

  4. #4
    Join Date
    Apr 2006
    Location
    Ohio
    Posts
    6,162
    Plugin Contributions
    0

    Default Re: Allow Customers To Upload Images Using Contact Us Page

    Gl,
    Way too sweet, thank for the information...
    Mark
    Hare Do

  5. #5
    Join Date
    Dec 2008
    Location
    Uk
    Posts
    79
    Plugin Contributions
    0

    Default Re: Allow Customers To Upload Images Using Contact Us Page

    Hi. I like your site very much, just a quick question, "How did you get the larger image when you hover over the product picture ?" I would like to incorporate this feature on my site, is it a mod or custom coding ?

    Cheers
    J#xx
    (Scott Perry)

  6. #6
    Join Date
    Apr 2006
    Location
    Ohio
    Posts
    6,162
    Plugin Contributions
    0

    Default Re: Allow Customers To Upload Images Using Contact Us Page

    J,
    That is a mod in the free software add on called Image Handler
    Mark
    Hare Do

  7. #7
    Join Date
    Feb 2008
    Posts
    1,336
    Plugin Contributions
    1

    Default Re: Allow Customers To Upload Images Using Contact Us Page

    Yes that is image handler 2 one of the best mods for Zen Cart

  8. #8
    Join Date
    Apr 2004
    Location
    UK
    Posts
    5,821
    Plugin Contributions
    2

    Default Re: Allow Customers To Upload Images Using Contact Us Page

    Quote Originally Posted by Glamorousshoe View Post
    I have managed to include an email form with the upload image form. Now if a customer upload an image to my website I get an email with all the customer information and the image is posted on my server. You can see it in action here: http://www.ohiospeedshop.com/gallery-c-298.html if anyone has a feedback or suggestion please let me know.
    Excellent..well done..just wondering why you did not use built in zencart attributes upload image/submit text options?

  9. #9
    Join Date
    Feb 2008
    Posts
    1,336
    Plugin Contributions
    1

    Default Re: Allow Customers To Upload Images Using Contact Us Page

    As far as I remember the attribute approach require that the customer upload the image at the time of purchase. What I am trying to do is build an online showcase to show the customers car's or even anyone that is looking for a place to show off their cars. In most cases they will have to receive the product and install it on their car before they can send a picture to me. Which meant that I had to come up with a way to have the images uploaded to my site, the problem was that I would have to check my images folder everyday so I decided to merge an image upload script with an email script so every time an image is uploaded I will receive an email with all the car information.

    It took me a few hours to get it to work I think that's normal for an amateur.

  10. #10
    Join Date
    Apr 2004
    Location
    UK
    Posts
    5,821
    Plugin Contributions
    2

    Default Re: Allow Customers To Upload Images Using Contact Us Page

    As far as I remember the attribute approach require that the customer upload the image at the time of purchase.
    Understood, but could have made a hidden product, free of charge, then add option to upload image with text..

 

 
Page 1 of 4 123 ... LastLast

Similar Threads

  1. v138a Only allow logged in customers to use contact form?
    By joannem in forum General Questions
    Replies: 5
    Last Post: 11 Feb 2013, 09:20 PM
  2. allow file upload on contact us page
    By bluelightnin6 in forum General Questions
    Replies: 5
    Last Post: 13 Jan 2012, 01:00 AM
  3. allow customers to upload an image?
    By davi2359 in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 7 Mar 2011, 10:30 AM
  4. Replies: 1
    Last Post: 5 Jun 2009, 05:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR