• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

Uploading an image using php on IIS 6.0

I am haviing a problem uploading images using php... one error I am getting is:

SELECT picid,pic_userid,toshow FROM picture WHERE pic_userid = '1'
Warning: move_uploaded_file(/Project1.jpg): failed to open stream: Permission denied in D:\Web Sites\HavenZone.com Dating\adminpanel\upload.php on line 31

Warning: move_uploaded_file(): Unable to move 'C:\WINDOWS\TEMP\php33.tmp' to '/Project1.jpg' in D:\Web Sites\HavenZone.com Dating\adminpanel\upload.php on line 31
error on moving


I get these errors if I try to upload from an admin page... and from a user page it says it uploaded but the file size is 0k... so the database (MYSQL) creates the file name but doesn't upload the file...

any ideas?

the upload.php file looks like this:

<?php
/* $Id: upload.php,v 1.0 2006-04-27 06:22:05-07 brian Exp brian $ */
// vim: expandtab sw=4 ts=4 sts=4:
session_start();

if (!isset($_COOKIE["AUTH_USER"])) {
    header("location: index.php");      
}
require_once("../config.php");
require_once("adminglobal.php");

if ($_POST['addpic']){
      $Q = "SELECT picid,pic_userid,toshow FROM picture WHERE pic_userid = '{$_POST[pic_userid]}'";
      echo $Q;
      $check=mysql_query($Q) or die(mysql_error());
      $getcheck = mysql_fetch_array($check);
      $numReturned = mysql_num_rows($check);
      
      $msgShow = "";
      if ($numReturned >= 5){
            $msgShow = "You cannot upload more than 5 photos";
            echo $msgShow;
      }
      else{
            $new_imagepath = $HTTP_POST_FILES['image_name']['tmp_name'];
            $pic = $HTTP_POST_FILES['image_name']['name'];
            $fileup = $upload_dir."/".$pic;
            //echo $_POST['image_name']['name'];
            if(is_uploaded_file($_FILES['image_name']['tmp_name'])){
                  $dest=$upload_dir."/".$_FILES['image_name']['name'];
                  if(move_uploaded_file($_FILES['image_name']['tmp_name'],$dest) or die("error on moving")){      
                        $msgShow = "image uploaded";
                  }
            }
            else{
                  $msgShow="Can't copy file";
            }
            echo $msgShow;
            /*if(is_uploaded_file($_POST["form_data"]["tmp_name"])){
                  $size = @getimagesize($_POST["form_data"]["tmp_name"]);
                  if ($_FILES["form_data"]['size']==0){
                        $msgShow = $ToSmallUpload;
                  } elseif ($_FILES["form_data"]["size"]>MAX_FILESIZE) {
                        $msgShow = $ToBigUpload;
                  } else {
                        if(!copy($_FILES["form_data"]["tmp_name"],$upload_dir."/".$_FILES["form_data"]["name"])) {
                              $msgShow = $CopyFail;
                        }
                        $local_pic = $_FILES["form_data"]["name"];
                  }*/
//            } else {
//                  $msgShow = $noimageadded;
//            }
            echo $msgShow;
      }
      if($msgShow==""){
            $U = "INSERT into $pic_tbl (picid,pic_userid,picture,picdate,status,toshow) ";
            $U.= "VALUES ('','".$_POST['pic_userid']."','$pic','".time()."','$SetPicturePending',0) ";
            $id = mysql_insert_id();
            $result1=mysql_query($U) or die(mysql_error());
            $msgShow = $upload_success;
            echo "&nbsp;".$U."&nbsp;".$msgShow;
    } else {

    }
      //include("photos.php?action=list&pic_userid=$pic_userid&msgShow=$msg_show");
      //pic_userid=$_POST[pic_userid];
      $action="list";
      echo $msg_show;
//      include("photos.php");
   // echo  "<div class=\"error\">$msg_show!!</div><br />\n";
   echo  "<META HTTP-EQUIV=\"Refresh\" Content=\"2;URL=photos.php?action=list&pic_userid=$pic_userid\">";
}      
?>
0
Gregg Battaglia
Asked:
Gregg Battaglia
  • 8
  • 5
1 Solution
 
Gregg BattagliaAuthor Commented:
if you would like to see the page I am working on it is at http://dating.havenzone.com 

when you sign up for a user account everything works fine but when you go to upload a photo it says it went then bounces you out of your account... I am trying to find out why this is happening... I am not sure if it is a permissions issue with IIS or something in the php.
0
 
Richard QuadlingSenior Software DeverloperCommented:
Hi Gregg1009,

Quick question, where is $upload_dir defined and does it exist?


Before you execute the move_uploaded_file() function can you do a simply echo  of the $dest

Regards,

Richard Quadling.
0
 
Gregg BattagliaAuthor Commented:
the $upload_dir is defined in the config.php which looks like this:

<?php
/* $Id: config.php,v 1.0 2006-04-27 06:16:33-07 brian Exp brian $ */
// vim: expandtab sw=4 ts=4 sts=4:

       /* Set your language...
       Code: eng for english, nor for norwegian or other... */
       $language = "eng";

       $siteurl = "http://".$_SERVER['SERVER_NAME']; // no ending slash

       /* for IIS users you will need to add this manually.
       eg: c:/Inet/www/path/script_name
       */
       define('FULL_PATH', "D:/Web Sites/HavenZone.com Dating"); //no ending slash.
     
    /* How many members do you want per page*/
          $admin_member_per_page = 25;
       /* Number of ads per each page  */
       $number_of_ads_per_page = 5;


     define('MEDIA_DIR',"$siteurl/pictures");  // Full url of the media directory, no ending slash.
     define('UPLOAD_DIR',FULL_PATH."/pictures");  // Full path of the media directory, no ending slash.
     define('MODULE_DIR',"modules");  // The module directory, no slashes.
     
     define('MAX_FILESIZE',"29000");   /* max file size for picture upload */
     define('MAXIMAGE_W_SIZE',"100");  // defines max image width size for thumbnail images
     define('MAXIMAGE_H_SIZE',"100");  // defines max image height size for thumbnail images

     define('FLOOD_TIMEOUT',"1800");  // defines max time they have to wait before sending messages. used for slowing down spam


     /* Your emailadress. BE SURE TO SET. */

       define('FROM', "Romance@HavenZone.com");

     define('CURRENCY', "$");
     define('CURRENCY_CODE', "USD"); // used mostly with paypal

     /* payment processors here PAYPAL*/
     define('FROM_PAYPAL',"GBattaglia@HavenZone.com");
     define('ITEM_NAME',"HavenZone Personals");


    /* Worldpay */
     define('INSTID',"123456"); // worlpay login #

     /*2Checkout*/
     define('SERIAL_ID',"123456"); // 2checkout login #

     /* Mysql Table prefix must be set here */
       define('TABLE_PREFIX',"dating.");

     define('CHARSET',"iso-8859-1"); // charset for content_type. only use iso-8859-1 or utf-8
     
    // set to on (1) it will NOT clean out the session db table automatically.
     // set this to 0 AFTER you have completed the install.
     $GLOBALS['noshutdownfunc'] = 0;

        // Do not edit below unless you change install directory:
     @header("Cache-control: private");
include_once(FULL_PATH."/adminpanel/func.php");

?>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Richard QuadlingSenior Software DeverloperCommented:
Ah.

With ...

 define('UPLOAD_DIR',FULL_PATH."/pictures");

you are defining a CONSTANT not a VARIABLE.

So.

Try ...

  $fileup = UPLOAD_DIR . DIRECTORY_SEPARATOR . $pic;

instead.

Use DIRECTORY_SEPARATOR to maintain windows/unix compatibility too.
0
 
Gregg BattagliaAuthor Commented:
I still get this:

SELECT picid,pic_userid,toshow FROM picture WHERE pic_userid = '1'
Warning: move_uploaded_file(/Project1.jpg): failed to open stream: Permission denied in D:\Web Sites\HavenZone.com Dating\adminpanel\upload.php on line 31

Warning: move_uploaded_file(): Unable to move 'C:\WINDOWS\TEMP\php37.tmp' to '/Project1.jpg' in D:\Web Sites\HavenZone.com Dating\adminpanel\upload.php on line 31
error on moving
0
 
Richard QuadlingSenior Software DeverloperCommented:
Can you echo $fileup and $dest please JUST BEFORE you run the move_uploaded_file().
0
 
Gregg BattagliaAuthor Commented:
sorry I am not very good with php scripting... should that just be two seporate lines the read

echo $fileup;
echo $dest;


so it would look like this:


            $new_imagepath = $HTTP_POST_FILES['image_name']['tmp_name'];
            $pic = $HTTP_POST_FILES['image_name']['name'];
                                echo $fileup;
                                echo $dest;
            $fileup = $upload_dir."/".$pic;
            //echo $_POST['image_name']['name'];
            if(is_uploaded_file($_FILES['image_name']['tmp_name'])){
                  $dest=$upload_dir."/".$_FILES['image_name']['name'];
                  if(move_uploaded_file($_FILES['image_name']['tmp_name'],$dest) or die("error on moving")){      
                        $msgShow = "image uploaded";
0
 
Richard QuadlingSenior Software DeverloperCommented:
Try...

$new_imagepath = $HTTP_POST_FILES['image_name']['tmp_name'];
$pic = $HTTP_POST_FILES['image_name']['name'];
$fileup = UPLOAD_DIR . DIRECTORY_SEPARATOR . $pic;
//echo $_POST['image_name']['name'];
if(is_uploaded_file($_FILES['image_name']['tmp_name']))
      {
      $dest = UPLOAD_DIR . DIRECTORY_SEPARATOR . $_FILES['image_name']['name'];
      if(move_uploaded_file($_FILES['image_name']['tmp_name'],$dest) or die("error on moving"))
            {    
            $msgShow = "image uploaded";
            }
      }



What is $fileup used for? Remove that too if not used.
0
 
Gregg BattagliaAuthor Commented:
now I get this to flash real quick:

SELECT picid,pic_userid,toshow FROM picture WHERE pic_userid = '1'image uploadedimage uploaded


from the admin page it uploads the file but it doesn't show in the database... and from the end user page it does the same thing creates the file but with 0k
0
 
Gregg BattagliaAuthor Commented:
I noticed on the side of that page it says:


Warning: main(/templates/include_right.php): failed to open stream: No such file or directory in D:\Web Sites\HavenZone.com Dating\templates\errormsg.html.php on line 55

Warning: main(/templates/include_right.php): failed to open stream: No such file or directory in D:\Web Sites\HavenZone.com Dating\templates\errormsg.html.php on line 55

Warning: main(): Failed opening '/templates/include_right.php' for inclusion (include_path='.;D:\php4\includes\pear') in D:\Web Sites\HavenZone.com Dating\templates\errormsg.html.php on line 55


this only happens after the upload bombs out... it just doesn't load teh side bar... from the user page you still get the same result.
0
 
Richard QuadlingSenior Software DeverloperCommented:
How much of this IS working?

0
 
Gregg BattagliaAuthor Commented:
everything except the upload of the photos... this is the only part that is not going through...

what I noticed since I made the change you suggested...

in the admin page the upload goes through but it does not rename the file nor does it show in the database but the complete file does upload into the dir

and on the user side the upload looks like it went but in the dir there is the new name file with 0k and once it bombs out of the upload to forgets where it was with the scripts.
0
 
Gregg BattagliaAuthor Commented:
the main fix to this was the locatcation of the php temp directory. by default it installs the php temp to the windows temp directory it needed to be changed in the php.ini file


that was the fix
0
 
GranModCommented:
PAQed with points refunded (500)

GranMod
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now