www.webdeveloper.com
Page 15 of 23 FirstFirst ... 51314151617 ... LastLast
Results 211 to 225 of 340

Thread: How to: Upload images using PHP

  1. #211
    Join Date
    Mar 2006
    Location
    Liverpool, UK
    Posts
    278
    PHP Code:
    $directory_self str_replace(basename($_SERVER['PHP_SELF']), ''$_SERVER['PHP_SELF']); 

    $scrolluploaddir 'scrolllargeimages/'
    $thumbuploaddir 'thumbarticleimages/';
    $uploaddir 'articleimages/';

    $uploadSuccess 'http://' $_SERVER['HTTP_HOST'] . $directory_self 'multiple.upload.success.php'

    $fieldname 'file'

    $errors = array(=> 'php.ini max file size exceeded'
                    
    => 'html form max file size exceeded'
                    
    => 'file upload was only partial'
                    
    => 'no file was attached'); 

    $active_keys = array(); 
    foreach(
    $_FILES[$fieldname]['name'] as $key => $filename

        if(!empty(
    $filename)) 
        { 
            
    $active_keys[] = $key
        } 
    }
     

    $sizearray=sizeOf($active_keys); 

    $caps = array();
    foreach (
    $_POST['caption'] as $key => $value) {
     
    $caps[] = $value;
    }
     
    if (!(
    $sizearray==0)) { 

    count($active_keys
        or 
    error('No files were uploaded'$uploadform);

    foreach(
    $active_keys as $key

        (
    $_FILES[$fieldname]['error'][$key] == 0
            or 
    error($_FILES[$fieldname]['tmp_name'][$key].': '.$errors[$_FILES[$fieldname]['error'][$key]], $uploadForm); 

         
    foreach(
    $active_keys as $key

        @
    is_uploaded_file($_FILES[$fieldname]['tmp_name'][$key]) 
            or 
    error($_FILES[$fieldname]['tmp_name'][$key].' not an HTTP upload'$uploadForm); 

         
    foreach(
    $active_keys as $key

        @
    getimagesize($_FILES[$fieldname]['tmp_name'][$key]) 
            or 
    error($_FILES[$fieldname]['tmp_name'][$key].' not an image'$uploadForm); 


     
    $time time();
       
    $p=0;
         
    foreach(
    $active_keys as $key)  
    {  
        while(
    file_exists($uploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key]))  
        {  
            
    $time++;  
        }  
        
    $uploadfilename[$key] = $uploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key]; 

        @
    move_uploaded_file($_FILES[$fieldname]['tmp_name'][$key], $uploadfilename[$key])  
            or 
    error('receiving directory insufficient permission'$uploadform);

    $image$time.'-'.$_FILES[$fieldname]['name'][$key]; 

      
    $desc $caps[$key];
      
     
    $q "INSERT INTO articleimages (article, imgLoc, caption) VALUES ('$articleID', '$image', '$desc')"
     
    $s mysql_query($q) or die("Error!! BAD INSERT INTO STATEMENT 23!"); 

    $e strrpos($uploadfilename[$key],"."); 
    if (!
    $e) { $e==0; } 

    $l strlen($uploadfilename[$key]) - $e
    $pext substr($uploadfilename[$key],$e+1,$l); 
    $ext strtolower($pext); 

    $imgw=290

    $imgdim getimagesize($uploadfilename[$key], $imageinfo); 

        if (
    $ext == "jpeg" || $ext == "jpg") { 
            if (
    $imgdim[0] > $imgw
                { 
         
    $imgSrc=$uploadfilename[$key];
         
    $org_img=imagecreatefromjpeg($imgSrc);
         
    $origWidth imagesx($org_img);
            
    $origHeight imagesy($org_img);
      
      if (
    $key==0) {
         
    $img imagecreatetruecolor(405405); 
         
    imagecopyresampled($img$org_img0000405405$origWidth$origHeight); 
               
    imagejpeg($img$scrolluploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key], 80); 
               
    imagedestroy($img);
       }
         
      
    $divider $imgdim[0] / 70;
      
    $fin_h $imgdim[1] / $divider;
         
    $timg imagecreatetruecolor(70$fin_h); 
         
    imagecopyresampled($timg$org_img000070$fin_h$origWidth$origHeight); 
               
    imagejpeg($timg$thumbuploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key], 80); 
               
    imagedestroy($timg);
       
                    
    $final_imgw $imgw
                    
    $final_imgh $imgdim[1] * ($imgw $imgdim[0]); 
                    
    $img imagecreatetruecolor($final_imgw$final_imgh); 
                    
    $org_img imagecreatefromjpeg($uploadfilename[$key]); 
                    
    imagecopyresampled($img$org_img0000$final_imgw$final_imgh$imgdim[0], $imgdim[1]); 
                    
    imagejpeg($img$uploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key], 80); 
                    
    imagedestroy($img); 
                } 
            else { 
                    
    $final_img $uploadfilename[$key]; 
        
        
    $imgSrc=$uploadfilename[$key];
         
    $org_img=imagecreatefromjpeg($imgSrc);
         
    $origWidth imagesx($org_img);
            
    $origHeight imagesy($org_img);
      
      if (
    $key==0) {
         
    $img imagecreatetruecolor(405405); 
         
    imagecopyresampled($img$org_img0000405405$origWidth$origHeight); 
               
    imagejpeg($img$scrolluploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key], 80); 
               
    imagedestroy($img);
      }
         
      
    $divider $imgdim[0] / 70;
      
    $fin_h $imgdim[1] / $divider;
         
    $timg imagecreatetruecolor(70$fin_h); 
         
    imagecopyresampled($timg$org_img000070$fin_h$origWidth$origHeight); 
               
    imagejpeg($timg$thumbuploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key], 80); 
               
    imagedestroy($timg);
                } 
        } 
         
        elseif (
    $ext == "gif" || $ext == "giff") { 
            if (
    $imgdim[0] > $imgw
                { 
         
    $imgSrc=$uploadfilename[$key];
         
    $org_img=imagecreatefromgif($imgSrc);
         
    $origWidth imagesx($org_img);
            
    $origHeight imagesy($org_img);
      
      if (
    $key==0) {
         
    $img imagecreatetruecolor(405405); 
         
    imagecopyresampled($img$org_img0000405405$origWidth$origHeight); 
               
    imagegif($img$scrolluploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key]); 
               
    imagedestroy($img);
       }
         
      
    $divider $imgdim[0] / 70;
      
    $fin_h $imgdim[1] / $divider;
         
    $timg imagecreatetruecolor(70$fin_h); 
         
    imagecopyresampled($timg$org_img000070$fin_h$origWidth$origHeight); 
               
    imagegif($timg$thumbuploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key]); 
               
    imagedestroy($timg);
       
                    
    $final_imgw $imgw
                    
    $final_imgh $imgdim[1] * ($imgw $imgdim[0]); 
                    
    $img imagecreatetruecolor($final_imgw$final_imgh); 
                    
    $org_img imagecreatefromgif($uploadfilename[$key]); 
                    
    imagecopyresampled($img$org_img0000$final_imgw$final_imgh$imgdim[0], $imgdim[1]); 
                    
    imagegif($img$uploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key]); 
                    
    imagedestroy($img); 
                } 
            else { 
                    
    $final_img $uploadfilename[$key]; 
        
        
    $imgSrc=$uploadfilename[$key];
         
    $org_img=imagecreatefromgif($imgSrc);
         
    $origWidth imagesx($org_img);
            
    $origHeight imagesy($org_img);
      
      if (
    $key==0) {
         
    $img imagecreatetruecolor(405405); 
         
    imagecopyresampled($img$org_img0000405405$origWidth$origHeight); 
               
    imagegif($img$scrolluploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key]); 
               
    imagedestroy($img);
      }
         
      
    $divider $imgdim[0] / 70;
      
    $fin_h $imgdim[1] / $divider;
         
    $timg imagecreatetruecolor(70$fin_h); 
         
    imagecopyresampled($timg$org_img000070$fin_h$origWidth$origHeight); 
               
    imagegif($timg$thumbuploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key]); 
               
    imagedestroy($timg);
                } 
        } 
         
        elseif (
    $ext == "png") { 
            if (
    $imgdim[0] > $imgw
                { 
         
    $imgSrc=$uploadfilename[$key];
         
    $org_img=imagecreatefrompng($imgSrc);
         
    $origWidth imagesx($org_img);
            
    $origHeight imagesy($org_img);
      
      if (
    $key==0) {
         
    $img imagecreatetruecolor(405405); 
         
    imagecopyresampled($img$org_img0000405405$origWidth$origHeight); 
               
    imagepng($img$scrolluploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key]); 
               
    imagedestroy($img);
     }
         
      
    $divider $imgdim[0] / 70;
      
    $fin_h $imgdim[1] / $divider;
         
    $timg imagecreatetruecolor(70$fin_h); 
         
    imagecopyresampled($timg$org_img000070$fin_h$origWidth$origHeight); 
               
    imagepng($timg$thumbuploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key]); 
               
    imagedestroy($timg);
       
                    
    $final_imgw $imgw
                    
    $final_imgh $imgdim[1] * ($imgw $imgdim[0]); 
                    
    $img imagecreatetruecolor($final_imgw$final_imgh); 
                    
    $org_img imagecreatefrompng($uploadfilename[$key]); 
                    
    imagecopyresampled($img$org_img0000$final_imgw$final_imgh$imgdim[0], $imgdim[1]); 
                    
    imagepng($img$uploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key]); 
                    
    imagedestroy($img); 
                } 
            else { 
                    
    $final_img $uploadfilename[$key]; 
        
        
    $imgSrc=$uploadfilename[$key];
         
    $org_img=imagecreatefrompng($imgSrc);
         
    $origWidth imagesx($org_img);
            
    $origHeight imagesy($org_img);
      
      if (
    $key==0) {
         
    $img imagecreatetruecolor(405405); 
         
    imagecopyresampled($img$org_img0000405405$origWidth$origHeight); 
               
    imagepng($img$scrolluploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key]); 
               
    imagedestroy($img);
     }
         
      
    $divider $imgdim[0] / 70;
      
    $fin_h $imgdim[1] / $divider;
         
    $timg imagecreatetruecolor(70$fin_h); 
         
    imagecopyresampled($timg$org_img000070$fin_h$origWidth$origHeight); 
               
    imagepng($timg$thumbuploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key]); 
               
    imagedestroy($timg);
                } 
        } 
         
        else { 
      
    unlink($uploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key]);
      
    error('You have chosen an image file format that is not supported'$uploadform); } 
         
    }  



  2. #212
    Join Date
    Mar 2006
    Location
    Liverpool, UK
    Posts
    278
    and finally this part creates the articles to be added to the scroll bar
    PHP Code:
    function error($error$location$seconds 5

        
    header("Refresh: $seconds; URL=\"$location\""); 
        echo 
    '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n"
        
    '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n"
        
    '<html lang="en">'."\n"
        
    '    <head>'."\n"
        
    '        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n"
        
    '        <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n"
        
    '    <title>Upload error</title>'."\n\n"
        
    '    </head>'."\n\n"
        
    '    <body>'."\n\n"
        
    '    <div id="Upload">'."\n\n"
        
    '        <h1>Upload failure</h1>'."\n\n"
        
    '        <p>An error has occured: '."\n\n"
        
    '        <span class="red">' $error '...</span>'."\n\n"
        
    '         The upload form is reloading</p>'."\n\n"
        
    '     </div>'."\n\n"
     
    '    <body>'.
        
    '</html>';
        exit; 


    $sql="select articleID, title, snippet from article where scrollbar='Yes' AND now() > publishingdate ORDER BY articleID DESC LIMIT 0,5";
    $result=mysql_query($sql) or die ("Error!! BAD SELECT SEARCH STATEMENT!!");
    $nrows mysql_num_rows($result);

    for(
    $i=0;$i<$nrows;$i++) {
     
    $row mysql_fetch_array($result);
     
    extract($row);
     
    $articleIDs[]=$articleID;
     
    $titles[]=$title;
     
    $snippets[]=$snippet;
    }

    $arts=sizeOf($articleIDs);

    for(
    $k=0;$k<$arts;$k++) {
     
    $sql2="SELECT Min(imgID) as minimage, imgLoc from articleimages WHERE article='$articleIDs[$k]' group by article";     
     
    $result2=mysql_query($sql2) or die ("Error!! BAD SELECT SEARCH STATEMENT!!"); 
     
      
    $row2 mysql_fetch_array($result2);
      
    extract($row2);
     
      
    $imLoc[]=$imgLoc
     }

    $arrayimage=sizeOf($imLoc);


    $cant=$nrows+1;

    $string "cant=$cant&";

    $t='1';

    for (
    $i=0;$i<$arrayimage;$i++) {
     
    $string .= "image$t=http://www.xxxxxx.com/xxxxxx/xxxxx/xxxxxxxxx/$imLoc[$i]&";
     
    $t++;
    }

    $t='1';

    for (
    $i=0;$i<$arrayimage;$i++) {
     
    $string .= "t$t=http://www.xxxxxxxl.com/xxxx/xxxxxxxxxx/xxxxxxxxx/$imLoc[$i]&";
     
    $t++;
    }

    $t='1';

    for (
    $i=0;$i<$arts;$i++) {
     
    $string .= "text$t=<p><b><font color='#980000' font-family='Verdana' size='14'>$titles[$i]</font></b></p><p><br/><font-family='Verdana' font-size='11px'>$snippets[$i]</font></p>&";
     
    $t++;
    }

    $t='1';
    $arts2=$arts-1;

    for (
    $i=0;$i<$arts;$i++) {
     if (
    $i==$arts2) {
      
    $string .= "id$t=$articleIDs[$i]";
     }
     else {
      
    $string .= "id$t=$articleIDs[$i]&";
     }
     
    $t++;
    }

    $txtfile="../flashnews.txt";
    $file fopen($txtfile'w') or die("can't open file");   
     
    fwrite($file$string);

      
    fclose($file);

    header("Location: ../success.php"); 
    exit;

    ?> 
    By the fact that Ive just had to submit my code to 3 different posts sorts of answers my question here but would you recommend me to split this code into three different parts similar to the way I have just done it here? Also the upload images script where it resizes this is rather huge is there a way of compressing this?

    Regards

    Mike
    Last edited by cs3mw; 07-23-2008 at 07:59 AM.

  3. #213
    Join Date
    Mar 2006
    Location
    Liverpool, UK
    Posts
    278
    to be honest scrap that last thought because I have a simple images upload without an article and once I try and upload that first picture i.e. the 4842px * 2102px I am getting the same error message. I have removed the maxium filesize from the original form if that helps.

    Regards

  4. #214
    Join Date
    Oct 2006
    Location
    On the web, working on my website
    Posts
    184
    Alright, i am wondering how i would do this:

    I am trying to have an uploading page on my website. When members submit the entry, the entry goes to either the photo page (so .gif, .jpg, .png, etc.) and documents go to the documents page. When they go to the pages, the images would actually put themselves onto the page (so when visitors go to the page they can see the picture, not link to the picture). When they go to the documents page they are given links. Is there a way to do this.


    Also, i was wondering if there was any administrator tools that would allow me to accept them to be put up, or delete the ones that are not acceptable?

    Thanks for your help.

  5. #215
    Join Date
    Jul 2008
    Posts
    36
    Thanks Bokeh!! This coding worked perfect and has been a huge help since I have limited php experience. Does anyone know an add on script that i can put in so that after a file is uploaded an email is sent to notify the business that a file has been uploaded?

  6. #216
    Join Date
    Oct 2006
    Location
    On the web, working on my website
    Posts
    184
    *bumidy Bump*

  7. #217
    Join Date
    Jul 2008
    Posts
    36
    what the heck does that mean?

  8. #218
    Join Date
    Apr 2007
    Posts
    133
    I am using the main script with success. I am using bokeh's script because of its usability. I did develop a thumbnail script from various sorces but cannot get it working with bokehs cript i think because of the now() timestamp that is used. Is there any way around this?


    PHP Code:
    $id=$_POST['id'];
    // filename: upload.processor.php

    // first let's set some variables

    // make a note of the current working directory, relative to root.
    $directory_self str_replace(basename($_SERVER['PHP_SELF']), ''$_SERVER['PHP_SELF']);

    // make a note of the directory that will recieve the uploaded file
    $uploadsDirectory 'uploaded_files/';

    // make a note of the location of the upload form in case we need it
    $uploadForm 'http://' $_SERVER['HTTP_HOST'] . $directory_self 'upload.success.php';

    // make a note of the location of the success page
    $uploadSuccess 'http://' $_SERVER['HTTP_HOST'] . $directory_self 'upload.success.php';

    // fieldname used within the file <input> of the HTML form
    $fieldname 'file';

    // Now let's deal with the upload

    // possible PHP upload errors
    $errors = array(=> 'php.ini max file size exceeded',
                    
    => 'html form max file size exceeded',
                    
    => 'file upload was only partial',
                    
    => 'no file was attached');

    // check the upload form was actually submitted else print the form
    isset($_POST['submit'])
        or 
    error('the upload form is neaded'$uploadForm);

    // check for PHP's built-in uploading errors
    ($_FILES[$fieldname]['error'] == 0)
        or 
    error($errors[$_FILES[$fieldname]['error']], $uploadForm);
        
    // check that the file we are working on really was the subject of an HTTP upload
    @is_uploaded_file($_FILES[$fieldname]['tmp_name'])
        or 
    error('not an HTTP upload'$uploadForm);
        
    // sample filename: 1140732936-filename.jpg
    $now time();
    while(
    file_exists($uploadFilename $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
    {
       
    $now++;
    }


    move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename);


              
       function 
    createThumbnail($imageDirectory$imageName$thumbDirectory$thumbWidth)
    {
      
    $im = @imagecreatefromjpeg($uploadFilename);
            if(
    $im) {
                
    $width imagesx($im);
                
    $height imagesy($im);
                
    $scale min150 $width150 $height);
                
    $newwidth $width $scale;
                
    $newheight =$height $scale;
                
    $im2 imagecreatetruecolor($newwidth$newheight);

                
    imagecopyresampled($im2$im0000$newwidth$newheight$width$height);

                
    imagejpeg($im2$thumbDirectory$uploadFilename);
                }
            }
        
    createThumbnail("uploaded_files"$uploadFilename"uploaded_files/thumbs" ,100); 

    include(
    "db.info.php");
    mysql_connect($host,$username,$password);
    mysql_select_db($database) or die( "Unable to select database");;



    //add info to database to link to uploaded files
    $upload $now.'-'.$_FILES[$fieldname]['name'];
    $query "UPDATE my_table SET file = '$upload' WHERE id = '$id'";
    $file mysql_real_escape_string($_POST['file']);
    $result mysql_query($query) or die ("Could not run query.");

    // If you got this far, everything has worked and the file has been successfully saved.
    // We are now going to redirect the client to a success page.
    header('Location: ' $uploadSuccess);

    // The following function is an error handler which is used
    // to output an HTML error page if the file upload fails
    function error($error$location$seconds 2)
    {
        
    header("Refresh: $seconds; URL=\"$location\"");
        echo 
    '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
        
    '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
        
    '<html lang="en">'."\n".
        
    '    <head>'."\n".
        
    '        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n".
        
    '        <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
        
    '    <title>Upload error</title>'."\n\n".
        
    '    </head>'."\n\n".
        
    '    <body>'."\n\n".
        
    '    <div id="Upload">'."\n\n".
        
    '        <h1>Upload failure</h1>'."\n\n".
        
    '        <p>An error has occured: '."\n\n".
        
    '        <span class="red">' $error '...</span>'."\n\n".
        
    '         The upload form is reloading</p>'."\n\n".
        
    '     </div>'."\n\n".
        
    '</html>';
        exit;
    // end error handler
    ?> 
    any ideas/thoughts greatly appreciated, pullin my hair out!!!!!

  9. #219
    Join Date
    Aug 2008
    Posts
    3
    There is a built in function:

    Check out http://php.net/fgetcsv

    and also check out use of list in this code sample

    http://www.java2s.com/Code/Php/Devel...adacsvfile.htm

  10. #220
    Join Date
    Apr 2007
    Posts
    133
    Now sorted the thumbnail application to work with the image upload, here is the script for others

    PHP Code:

    //place code between move_uploaded_file and database name INSERT
    move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename);


    //create thumbnail and place in thumbs directory

    $thumbDirectory "uploaded_files/thumbs/";
    $upload "$uploadFilename"//current image location
    $uploadTFilename $thumbDirectory.$now.'-'.$_FILES[$fieldname]['name'];

    $im imagecreatefromjpeg($upload);
            if(
    $im) {
                
    $width imagesx($im);
                
    $height imagesy($im);
                
    $scale min150 $width150 $height);
                
    $newwidth $width $scale;
                
    $newheight =$height $scale;
                
    $im2 imagecreatetruecolor($newwidth$newheight);

                
    imagecopyresampled($im2$im0000$newwidth$newheight$width$height);
                
    imagejpeg($im2$uploadTFilename100) or die('Problem In saving, please try again');
                }

    include(
    "dbconn.inc.php");
    mysql_connect($host,$username,$password);
    mysql_select_db($database) or die( "Unable to select database");

    $uploadname $now.'-'.$_FILES[$fieldname]['name'];
    $query "UPDATE my_table SET file = '$uploadname' WHERE id = '$id'";
    mysql_real_escape_string($uploadname);
    $result mysql_query($query) or die ("Could not run query.");
        
        
    // If you got this far, everything has worked and the file has been successfully saved.
    // We are now going to redirect the client to a success page.
    header('Location: ' $uploadSuccess);

    //rest of code error handling........... 

  11. #221
    Join Date
    Aug 2008
    Location
    Amarillo, TX
    Posts
    1

    Problems with Permissions

    Ok, here is what I am seeing. I am hosted on ulmb.com and they do not give you access to file permissions though they say it is automatic. They say I need to change the code to make it not check for permissions. Please tell me how I can do that. Also, I am wanting the uploads to be in Zip format only. Is there a way to make that happen instead of checking for images?

  12. #222
    Join Date
    Aug 2008
    Posts
    5

    Emailing Form Data problem

    Quote Originally Posted by CTWorion
    Wow, thanks a lot. I assume I can just plug this code into what already exists in upload.processor.php. Question though ... I received the email letting me know that an image had been uploaded, but the body of the email just said "message content." I understand that the value assigned to $form_data is 'message content' so that's where it came from. But I need it to actually write the content of the form in there.

    Do I have to define a variable for every field like:
    Code:
    @$Name = addslashes($_POST['Name']);
    @$email = addslashes($_POST['email']);
    Ok, the files upload beautifully, and the email actually emails to me, but, I'm having the same problem as CTWorion had, the information within the email just says "name". I've been trying to figure this out for days, obviously I'm a newbie, I don't know what I'm missing and I don't know how to make this work. Here's what I have done:

    On my order.form.php:

    <form enctype="multipart/form-data" action="upload.processor.php" method="post">
    <fieldset id="contact">
    <legend>Contact Information:</legend>
    <label for="name">Name:</label>
    <input type="text" name="name" id="name" />
    <label for="email">Email:</label>
    <input type="text" name="email" id="email" /><br>
    <label for="address">Address:</label>
    <input type="text" name="address" id="address" />
    <label for="phone">Phone:</label>
    <input type="text" name="phone" id="phone" />
    </fieldset>

    Here's what I have on my upload.processor.php:


    $fieldname = 'contact';
    $form_data = 'name';
    $to = 'query@mywebsite.com';
    $from = 'info@mywebsite.com';
    $subject = 'New Order';

    I don't know where to put the code that fixed this problem for CTWorion nor how to adjust it for my fields of information:

    Code:
    @$Name = addslashes($_POST['Name']);
    @$email = addslashes($_POST['email']);
    I hope that someone can help me. If I can just figure out how to get one of the fields to work, I should be able to apply that fix to other field areas, including the files area... I hope.

    Thank you.

  13. #223
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Quote Originally Posted by GusGallows
    They say I need to change the code to make it not check for permissions.
    The code doesn't check permissions. It just tries to write to the directory and if it can't the permissions must be wrong.

    If your webserver cannot write to the file system your only option is to store the images in the DB (or find a host that allows this).

  14. #224
    Join Date
    Aug 2008
    Posts
    5
    Quote Originally Posted by lcramer
    Ok, the files upload beautifully, and the email actually emails to me, but, I'm having the same problem as CTWorion had, the information within the email just says "name". ...
    On my order.form.php:

    <form enctype="multipart/form-data" action="upload.processor.php" method="post">
    <fieldset id="contact">
    <legend>Contact Information:</legend>
    <label for="name">Name:</label>
    <input type="text" name="name" id="name" />
    <label for="email">Email:</label>
    <input type="text" name="email" id="email" /><br>
    <label for="address">Address:</label>
    <input type="text" name="address" id="address" />
    <label for="phone">Phone:</label>
    <input type="text" name="phone" id="phone" />
    </fieldset>
    Slowly getting somewhere, I hope... I changed the code in the upload.processor.php a little bit and now I can at least get the text input for the field 'name' by having changed the code like this:

    $fieldname = 'contact';
    $form_data = ($_POST['name']);

    But now, I don't know what to add to have it also give me the text input for the other fields like 'email' or 'phone' or 'address'.

  15. #225
    Join Date
    Aug 2008
    Posts
    5

    email data from upload form trouble

    Used Bokeh's terrific upload script. Genius! But, I'm still working on trying to get it to email the information that was input from my website. Here's where I'm at now, the files upload successfully, the form emails to me successfully, figured out how to have the contact information print in the email but now I'm having trouble figuring out how to have it also give me the names of the files uploaded with the form.

    Here's the code from my upload.form.php:
    Code:
    <?php
    
    // filename: upload.form.php
    
    // first let's set some variables
    
    // make a note of the current working directory relative to root.
    $directory_self = str_replace(basename($_SERVER['/home/mysite/public_html/']), '', $_SERVER['/home/mysite/public_html/']);
    
    // make a note of the location of the upload handler
    $uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . '/upload.processor.php';
    
    // set a max file size for the html upload form
    $max_file_size = 500000; // size in bytes
    
    // now echo the html page
    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    
    <html lang="en">
    	<head>
    		<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    	
    		<link rel="stylesheet" type="text/css" href="stylesheet.css">
    		
    		<title>Upload form</title>
    	
    	</head>
    	
    	<body>
    	
    	<form action="<?php echo $uploadHandler ?>" method="post" enctype="multipart/form-data" name="Upload" id="Upload">
    	
    		<h1>
    		Inquiry / Order Upload Form</h1>
    	
    			<div id="order-form">
    	<form enctype="multipart/form-data" action="upload.processor.php" method="post">
    		<fieldset id="contact">
    		<legend><strong>Contact Information:</strong></legend>
    			<table width="45%" border="0">
                  <tr>
                    <td><label for="name">Name:</label>
                      <input type="text" name="name" id="name" /></td>
                    <td><label for="address">Address:</label>
                      <input type="text" name="address" id="address" />
                      <label for="label"></label></td>
                  </tr>
                  <tr>
                    <td><label for="email">Email:</label>
                      <input type="text" name="email" id="email" /></td>
                    <td><label for="phone">Phone &nbsp;&nbsp;:</label>
                      <input type="text" name="phone" id="phone" /></td>
                  </tr>
                  <tr>
                    <td colspan="2"><strong>Select Service Type:</strong>
                      <select name="select">
                        <option value="Select Here" selected>Select Here</option>
                        <option value="First">First</option>
                        <option value="Second">Second</option>
                        <option value="Third">Third</option>
                        <option value="Fourth">Fourth</option>
                      </select>                </td>
                  </tr>
                  <tr>
                    <td colspan="2"><p>&nbsp;</p>
                    </td>
                  </tr>
                </table>
    			<label for="name"></label>
    			<br>
    			<label for="address"></label>
    		</fieldset>
    
    		
    	  <p>
    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">
              </p>
    		<p>
              <label for="file1">Photo#1:</label>
              <input id="file1" type="file" name="file[]">
            </p>
    	
    		<p>
    			<label for="file2">Photo#2:</label>
    			<input id="file2" type="file" name="file[]">
    		</p>
    				
    		<p>
    			<label for="file3">Photo#3:</label>
    			<input id="file3" type="file" name="file[]">
    		</p>
    		<p>Describe service/s requested for each photo separately: </p>
    		<p>Service Description Photo#1
    		  <textarea name="textfield5" cols="75"></textarea>
    	  </p>
    		<p>Service Description Photo#2
              <textarea name="textfield6" cols="75"></textarea>
          </p>
    		<p>
    		  Service Description Photo#3 
    	      <textarea name="textfield7" cols="75"></textarea>
            </p>
    		<p>&nbsp;</p>
    		<p>&nbsp;</p>
    		<p>
    			<label for="submit">Press to...</label>
    			<input id="submit" type="submit" name="submit" value="Upload">
    		</p>
    		<p>&nbsp;</p>
    	</form>
    	
    	
    	</body>
    
    </html>

    will post the form.processor.php in the next one

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles