PHP unable to Upload to Fileserver

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Objectifnet
    New Member
    • Nov 2006
    • 7

    PHP unable to Upload to Fileserver

    Is there any one who could help with a problem. I have an application that uploads images to a file server with my upload directory set thus:[PHP]define('ALBUM_I MG_DIR', 'C:/Inetpub/wwwroot/sites/supportbridges/www/admin/profile/images/album/');[/PHP]

    This is how it is on my local computer running on IIS, now I want to transfer the same application to a Linux host. What can I do to shorten the directory link so as to be able to upload images to the same folder: The upload folder is "album"
  • underground
    New Member
    • Sep 2006
    • 41

    #2
    Originally posted by Objectifnet
    Is there any one who could help with a problem. I have an application that uploads images to a file server with my upload directory set thus:[PHP]define('ALBUM_I MG_DIR', 'C:/Inetpub/wwwroot/sites/supportbridges/www/admin/profile/images/album/');[/PHP]

    This is how it is on my local computer running on IIS, now I want to transfer the same application to a Linux host. What can I do to shorten the directory link so as to be able to upload images to the same folder: The upload folder is "album"
    How funny this I used this example toturial last week. Any how you need to change from c:/inetpub to something more like /home/www.domain/

    for the script to work. You must reflect the relitive path on the sever not your local computer.

    Comment

    • Objectifnet
      New Member
      • Nov 2006
      • 7

      #3
      Thanks for your help, I have set the relative part but it displays a blank page.

      My relative path is: /var/www/html/domains/supportbridges. org/documentroot/sbi/images/album/

      Please is there any suggestion why it keeps displaying a blank page instead of displayin the uploaded images.

      Comment

      • underground
        New Member
        • Sep 2006
        • 41

        #4
        It would be a big help if You showed the code because I can only guess...

        Comment

        • Objectifnet
          New Member
          • Nov 2006
          • 7

          #5
          Ok Thanks, here are the codes:
          The code below is my code for config. It defines the upload directory and also the database connection:

          [PHP]<?php
          # FileName="Conne ction_php_mysql .htm"
          # Type="MYSQL"
          # HTTP="true"
          $hostname_connx = "localhost" ;
          $database_connx = "sbdb";
          $username_connx = "root";
          $password_connx = "sbdbadm1n" ;
          $connx = mysql_pconnect( $hostname_connx , $username_connx , $password_connx ) or trigger_error(m ysql_error(),E_ USER_ERROR);

          // an album can have an image used as thumbnail
          // we save the album image here
          define("ALBUM_I MG_DIR", "/var/www/html/domains/supportbridges. org/documentroot/sbi/images/album/
          ");

          // all images inside an album are stored here
          define("GALLERY _IMG_DIR", "/var/www/html/domains/supportbridges. org/documentroot/sbi/images/gallery/"); ;

          // When we upload an image the thumbnail is created on the fly
          // here we set the thumbnail width in pixel. The height will
          // be adjusted proportionally
          define('THUMBNA IL_WIDTH', 40);

          // make a connection to mysql here
          $connx = mysql_connect ($hostname_conn x, $username_connx , $password_connx ) or die ("I cannot connect to the database because: " . mysql_error());
          mysql_select_db ($database_conn x) or die ("I cannot select the database '$dbname' because: " . mysql_error());
          ?>[/PHP]

          Now here is my functions code the handles the thumbnail creation and other stuff.

          [PHP]<?php
          # FileName="Conne ction_php_mysql .htm"
          # Type="MYSQL"
          # HTTP="true"
          $hostname_connx = "localhost" ;
          $database_connx = "sbdb";
          $username_connx = "root";
          $password_connx = "sbdbadm1n" ;
          $connx = mysql_pconnect( $hostname_connx , $username_connx , $password_connx ) or trigger_error(m ysql_error(),E_ USER_ERROR);

          // an album can have an image used as thumbnail
          // we save the album image here
          define("ALBUM_I MG_DIR", "/Inetpub/wwwroot/projects/support/images/album/");

          // all images inside an album are stored here
          define("GALLERY _IMG_DIR", "/Inetpub/wwwroot/projects/support/images/gallery/"); ;

          // When we upload an image the thumbnail is created on the fly
          // here we set the thumbnail width in pixel. The height will
          // be adjusted proportionally
          define('THUMBNA IL_WIDTH', 40);

          // make a connection to mysql here
          $connx = mysql_connect ($hostname_conn x, $username_connx , $password_connx ) or die ("I cannot connect to the database because: " . mysql_error());
          mysql_select_db ($database_conn x) or die ("I cannot select the database '$dbname' because: " . mysql_error());
          ?>[/PHP]

          Now here is my add album code the adds new album to the fileserver and database.

          [PHP]<?php
          require_once '../library/config.php';
          require_once '../library/functions.php';
          if(isset($_POST['txtName']))
          {
          $albumName = $_POST['txtName'];
          $albumDesc = $_POST['mtxDesc'];

          $imgName = $_FILES['fleImage']['name'];
          $tmpName = $_FILES['fleImage']['tmp_name'];

          // we need to rename the image name just to avoid
          // duplicate file names
          // first get the file extension
          $ext = strrchr($imgNam e, ".");

          // then create a new random name
          $newName = md5(rand() * time()) . $ext;

          // the album image will be saved here
          $imgPath = ALBUM_IMG_DIR . $newName;

          // resize all album image
          $result = createThumbnail ($tmpName, $imgPath, THUMBNAIL_WIDTH );

          if (!$result) {
          echo "Error uploading file";
          exit;
          }

          if (!get_magic_quo tes_gpc()) {
          $albumName = addslashes($alb umName);
          $albumDesc = addslashes($alb umDesc);
          }

          $query = "INSERT INTO tbl_album (al_name, al_description, al_image, al_date)
          VALUES ('$albumName', '$albumDesc', '$newName', NOW())";

          mysql_query($qu ery) or die('Error, add album failed : ' . mysql_error());

          // the album is saved, go to the album list
          echo "<script>window .location.href= 'index.php?page =list-album';</script>";
          exit;
          }
          ?>

          <form action="" method="post" enctype="multip art/form-data" name="frmAlbum" id="frmAlbum">
          <table width="100%" border="0" cellpadding="2" cellspacing="1" class="table_gr ey">
          <tr>
          <th width="150">Alb um Name</th>
          <td width="80" bgcolor="#FFFFF F"> <input name="txtName" type="text" id="txtName"></td>
          </tr>
          <tr>
          <th width="150">Des cription</th>
          <td bgcolor="#FFFFF F"> <textarea name="mtxDesc" cols="50" rows="4" id="mtxDesc"></textarea>
          </td>
          </tr>
          <tr>
          <th width="150">Ima ge</th>
          <td bgcolor="#FFFFF F"> <input name="fleImage" type="file" class="box" id="fleImage"> </td>
          </tr>
          <tr>
          <td width="150" bgcolor="#FFFFF F">&nbsp;</td>
          <td bgcolor="#FFFFF F"> <input name="btnAdd" type="submit" id="btnAdd" value="Add Album">
          <input name="btnCancel " type="button" id="btnCancel" value="Cancel" onClick="window .history.back() ;"></td>
          </tr>
          </table>
          </form>
          [/PHP]

          Now here is the page it ought to link to, the list-album page.

          [PHP]<?php
          $albumPerPage = 10;

          $pageNumber = isset($_GET['pageNum']) ? $_GET['pageNum'] : 1;

          $offset = ($pageNumber - 1) * $albumPerPage;
          $serial = $offset + 1;

          $sql = "SELECT al_id, al_name, al_image, COUNT(im_album_ id) AS al_numimage
          FROM tbl_album al LEFT JOIN tbl_image im ON al.al_id = im.im_album_id
          GROUP by al_id
          ORDER BY al_name ";
          $result = mysql_query($sq l . "LIMIT $offset, $albumPerPage") or die('Error, list album failed. ' . mysql_error());

          ?>
          <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="table_gr ey">
          <tr>
          <th width="30" align="center"> #</th>
          <th align="center"> Album Name</th>
          <th width="120" align="center"> Images</th>
          <th width="60" align="center"> &nbsp;</th>
          <th width="60" align="center"> &nbsp;</th>
          </tr>
          <?php
          if (mysql_num_rows ($result) == 0) {
          ?>
          <tr bgcolor="#FFFFF F">
          <td colspan="5">No album yet</td>
          </tr>
          <?php
          } else {
          $serial = $offset + 1;
          while ($row = mysql_fetch_ass oc($result)) {
          extract($row);

          $al_numimage = "<a href=\"?page=li st-image&album=$al _id\">$al_numim age</a>";
          ?>
          <tr bgcolor="#FFFFF F">
          <td width="30" align="center"> <?php echo $serial++; ?></td>
          <td align="center"> <a href="?page=alb um-detail&alId=<?p hp echo $al_id; ?>"><img src="../viewImage.php?t ype=album&name= <?php echo $row['al_image']; ?>" border="0" /><br />
          </a><a href="?page=alb um-detail&amp;alId =<?php echo $al_id; ?>"><?php echo $al_name; ?></a></td>
          <td width="120" align="center"> <?php echo $al_numimage; ?></td>
          <td width="60" align="center"> <a href="?page=mod ify-album&alId=<?ph p echo $al_id; ?>">Modify</a></td>
          <td width="60" align="center"> <a href="javascrip t:deleteAlbum(< ?php echo $al_id; ?>);">Delete</a></td>
          </tr>
          <?php
          } // end while
          }
          ?>
          <tr bgcolor="#FFFFF F">
          <td colspan="5" align="center"> <?php
          $result = mysql_query($sq l);
          $totalResults = mysql_num_rows( $result);

          echo getPagingLink($ totalResults, $pageNumber, $albumPerPage, "page=list-album");
          ?>&nbsp;</td>
          </tr>
          <tr bgcolor="#FFFFF F">
          <td colspan="5" align="right">< input type="button" name="btnAdd" value="Add Album" onclick="window .location.href= 'index.php?page =add-album';" /></td>
          </tr>
          </table>

          [/PHP]

          Please help, thanks.

          Comment

          • seangates
            New Member
            • Dec 2006
            • 19

            #6
            Originally posted by Objectifnet
            // resize all album image
            $result = createThumbnail ($tmpName, $imgPath, THUMBNAIL_WIDTH );
            I couldn't find the createThumbnail function anywhere. Is there more code than what you posted?

            Sean

            Comment

            Working...