View Single Post
Old 02-25-2008, 03:20 AM   #5 (permalink)
abiko
The Contributor
 
abiko's Avatar
 
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
abiko is on a distinguished road
Default

Edit: hehe Wildhoney - same post time :)
-----
oh.
YOu don't get 'adimagefile' in the $_POST -
there should on be adtitle, imagetype and url.

The adimagefile data, e.g. the data about the uploaded image is in $_FILES['adimagefile'].
Here's an array

PHP Code:
$file        =        array(                'tmp_name'    =>    $_FILES['adimagefile']['name'],
                                                                    
'tmp_type'    =>    $_FILES['adimagefile']['type'],
                                                                    
'tmp_file'    =>    $_FILES['adimagefile']['tmp_name'],
                                                                    
'tmp_size'    =>    $_FILES['adimagefile']['size']
                                                                ); 
And there you have :
  • tmp_name => the name of the file - (image1.jpg/image1.gif)
  • tmp_type => the type - image/jpeg, image/gif, image/png
  • tmpl_file => the path to the tmp file created by php in the tmp folder :)
  • tmp_size => the size of the image

Hope this works for you:
PHP Code:
<?php
$adtitle 
$_POST['adtitle'];
$adtype $_POST['adtype'];
$imagetype $_POST['imagetype'];
$url $_POST['url'];
$groupid $_POST['groupid'];
$file        =        array(                'tmp_name'    =>    $_FILES['adimagefile']['name'],
                                                                    
'tmp_type'    =>    $_FILES['adimagefile']['type'],
                                                                    
'tmp_file'    =>    $_FILES['adimagefile']['tmp_name'],
                                                                    
'tmp_size'    =>    $_FILES['adimagefile']['size']
                                                                );

   
$error false;
   
$errormessage "";

   if (
strlen($adtitle) < 1) {
      
$error true;
      
$errormessage .= "<li><b>Sorry.  You did not enter an ad title.</b><br>\n";
   }
     if (
strlen($url) < 1) {
         
$error true;
         
$errormessage .= "<li><b>Sorry.  You did enter a URL</b><br>\n";
      }

   }
    if (
strlen($code) < 1) {
                 
$error true;
                 
$errormessage .= "<li><b>Sorry.  You did not enter an affiliate code.</b><br>\n";
              }
              
              
if ( !
$error ) {    
    echo 
"<h2>Save new ad</h2>
<p>"
;
        if ( 
$file['tmp_type'] == 'image/jpeg' $file['tmp_type'] == 'image/gif') {
                            
// Upload
                              
$newfilename "../ads/$adid.$imagetype";
                    
$picfile $file['tmp_file'];
                    if ( 
move_uploaded_file$picfile$newfilename) ) {
                                
printf("Ad uploaded<br>");
                                
// Add to the DB                                  
                                           
switch ( $adtype) {
                                                case 
'A':
                                                 
$sql "insert into ads (adid, code, impressions, clicks, groupid, type, name) values ($adid, '$code', 1, 1, $groupid, '$adtype', '$adtitle')";
                                                break;    
                                                
                                                
// Right ad - upload and add to the DB
                                                
case 'O':
                                                     
$newurl "http://";
                                           
$newurl .= $url;
                                           
$sql "insert into ads (adid, image, url, impressions, clicks, groupid, type, name) values ($adid, '$imagetype', '$newurl', 1, 1, $groupid, '$adtype', '$adtitle')";                                                    
                                                break;
                                          }                                          
                                             
$result mysql_query($sql ,$db);
                                             
                                             if ( 
$result ) {
                                           
printf("<p>The ad has been added to the group.</p>");
                                           
printf("<p><a href=editadgroup.php?groupid=$groupid>Back to ad group</a></p>");
                                       } else {
                                           
printf"Error inserting into the DB");
                                       }
                            } else {
            
printf"Ad not uploaded");
                               } 
  echo 
"</p>";    
    } else {
                
printf "<li><b>Sorry.  You did not chose an image</b><br>\n";

          
} else {
      
printf("<font color=red>There was a problem creating the ad!</font><br><br>Please click on back in your browser to fix the problems listed below.<br>");
           
printf($errormessage);
    
}
__________________
Back from sysadmins to the programmers.
Send a message via ICQ to abiko Send a message via MSN to abiko
abiko is offline  
Reply With Quote
The Following User Says Thank You to abiko For This Useful Post:
gillweb (02-25-2008)