Zubrag.com
September 16, 2019, 04:36:20 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Upload file path error  (Read 10029 times)
Dhachi
Newbie
*
Posts: 2


« on: May 23, 2008, 06:48:03 AM »

For past many days I am trying to insert and upload facility in my site. Thanks to the script of uploading files provided by this site.I have come to half way. When I write full path of my destination folder(the one in which all my uploaded files are going to be stored) in my local PC the script works out fine. But when I uploaded my site on Server and changed the path of destination folder it doesn't work. It displays an error of "Destination folder does not exist or no permission to see it"..

If anyone knows how can I solve this problem please answer as soon as possible. My project is pending because of this.

I have written the following code :

----------------------------------------------------------------------------------------------------

<?php

require("connection.php");

   if(isset($_GET["adm"]))
   {
      $adm=$_GET["adm"];
   }
   else
   {

      session_start();
      $adm=$_SESSION["uid"];      
   }
####################################################################
# File Upload Form 1.0
####################################################################
# For updates visit http://www.zubrag.com/scripts/
####################################################################

####################################################################
#  SETTINGS START
####################################################################

// Folder to upload files to. Must end with slash /
define('DESTINATION_FOLDER','/www/photos/');

// Maximum allowed file size, Kb
// Set to zero to allow any size
define('MAX_FILE_SIZE', 0);
define('FLAG', 0);

// Upload success URL. User will be redirected to this page after upload.
define('SUCCESS_URL','http://upload_pics.php');

// Allowed file extensions. Will only allow these extensions if not empty.
// Example: $exts = array('avi','mov','doc');
$exts = array('jpg','jpeg','gif','png');

// rename file after upload? false - leave original, true - rename to some unique filename
define('RENAME_FILE', true);

// Need uploads log? Logs would be saved in the MySql database.
define('DO_LOG', true);

// MySql data (in case you want to save uploads log)
define('DB_HOST','localhost'); // host, usually localhost
define('DB_DATABASE','mydb'); // database name
define('DB_USERNAME','myusername'); // username
define('DB_PASSWORD','password-here'); // password

/* NOTE: when using log, you have to create mysql table first for this script.
Copy paste following into your mysql admin tool (like PhpMyAdmin) to create table
If you are on cPanel, then prefix _uploads_log on line 205 with your username, so it would be like myusername_uploads_log

CREATE TABLE _uploads_log (
  log_id int(11) unsigned NOT NULL auto_increment,
  log_filename varchar(128) default '',
  log_size int(10) default 0,
  log_ip varchar(24) default '',
  log_date timestamp,
  PRIMARY KEY  (log_id),
  KEY (log_filename)
);

*/

####################################################################
###  END OF SETTINGS.   DO NOT CHANGE BELOW
####################################################################

// Allow script to work long enough to upload big files (in seconds, 2 days by default)
@set_time_limit(172800);

// following may need to be uncommented in case of problems
// ini_set("session.gc_maxlifetime","10800");

function showUploadForm($message='') {
  $max_file_size_tag = '';
  if (MAX_FILE_SIZE > 0) {
    // convert to bytes
    $max_file_size_tag = "<input name='MAX_FILE_SIZE' value='".(MAX_FILE_SIZE*1024)."' type='hidden' >\n";
  }

  // Load form template
  include ('upload_pics.php');
}

// errors list
$errors = array();

$message = '';

// we should not exceed php.ini max file size
$ini_maxsize = ini_get('upload_max_filesize');
if (!is_numeric($ini_maxsize)) {
  if (strpos($ini_maxsize, 'M') !== false)
    $ini_maxsize = intval($ini_maxsize)*1024*1024;
  elseif (strpos($ini_maxsize, 'K') !== false)
    $ini_maxsize = intval($ini_maxsize)*1024;
  elseif (strpos($ini_maxsize, 'G') !== false)
    $ini_maxsize = intval($ini_maxsize)*1024*1024*1024;
}
if ($ini_maxsize < MAX_FILE_SIZE*1024) {
  $errors[] = "Alert! Maximum upload file size in php.ini (upload_max_filesize) is less than script's MAX_FILE_SIZE";
}

// show upload form
if (!isset($_POST['submit'])) {
  showUploadForm(join('',$errors));
}

// process file upload
else {
 
  while(true) {

    // make sure destination folder exists
    if (!@file_exists(DESTINATION_FOLDER)) {
      echo"Destination folder does not exist or no permissions to see it.";
      break;
    }

    // check for upload errors
    $error_code = $_FILES['txtp_path']['error'];
    if ($error_code != UPLOAD_ERR_OK) {
      switch($error_code) {
        case UPLOAD_ERR_INI_SIZE:
          // uploaded file exceeds the upload_max_filesize directive in php.ini
          echo"File is too big (1).";
          break;
        case UPLOAD_ERR_FORM_SIZE:
          // uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form
          echo"File is too big (2).";
          break;
        case UPLOAD_ERR_PARTIAL:
          // uploaded file was only partially uploaded.
          echo"Could not upload file (1).";
          break;
        case UPLOAD_ERR_NO_FILE:
          // No file was uploaded
          echo"Could not upload file (2).";
          break;
        case UPLOAD_ERR_NO_TMP_DIR:
          // Missing a temporary folder
          $errors[] = "Could not upload file (3).";
          break;
        case UPLOAD_ERR_CANT_WRITE:
          // Failed to write file to disk
          echo"Could not upload file (4).";
          break;
        case 8:
          // File upload stopped by extension
          echo "Could not upload file (5).";
          break;
      } // switch

      // leave the while loop
      break;
    }

    // get file name (not including path)
    $filename = @basename($_FILES['txtp_path']['name']);

    // filename of temp uploaded file
    $tmp_filename = $_FILES['txtp_path']['tmp_name'];

    $file_ext = @strtolower(@strrchr($filename,"."));
    if (@strpos($file_ext,'.') === false) { // no dot? strange
      echo"Suspicious file name or could not determine file extension.";
      break;
    }
    $file_ext = @substr($file_ext, 1); // remove dot

    // check file type if needed
    if (count($exts)) {   /// some day maybe check also $_FILES['user_file']['type']
      if (!@in_array($file_ext, $exts)) {
        echo"Files of this type are not allowed for upload.";
        break;
      }
    }

   
    // destination filename, rename if set to
    $dest_filename = $filename;
    if (RENAME_FILE) {
     
      $dest_filename = md5(uniqid('temp')) . '.' . $file_ext;
    }

    // get size
    $filesize = intval($_FILES["txtp_path"]["size"]); // filesize($tmp_filename);

    // make sure file size is ok
    if (MAX_FILE_SIZE > 0 && MAX_FILE_SIZE*1024 < $filesize) {
      echo"File is too big (3).";
      break;
    }

    if (!@move_uploaded_file($tmp_filename , DESTINATION_FOLDER . $dest_filename)) {
echo $tmp_filename;
echo "<br>";
echo $dest_filename;
echo "<br>";
echo DESTINATION_FOLDER;

      echo"Could not upload file (6).";
      define('FLAG', 1);

      break;
    }


   if('FLAG'<>1)
   {
   
          $query="insert into pictures(adm_id,date,p_path) values('$adm',now(),'$dest_filename')";
          $result=mysql_query($query)
          or
          die(mysql_error());

   }   

    // redirect to upload success url
    header('Location:upload_pics.php?pfile=');
    die();

    break;

  } // while(true)

  // Errors. Show upload form.
  $message = join('',$errors);
  showUploadForm($message);

}

?>

----------------------------------------------------------------------------------------------------

Logged
kellyjean81
Newbie
*
Posts: 6


« Reply #1 on: January 28, 2009, 02:52:58 PM »

I left out the "www/" part on mine because I am working on a subdomain with the user's access only to the subdomain's folder, and I stopped getting that error.
Logged
pipisdicelana
Newbie
*
Posts: 6


« Reply #2 on: February 05, 2009, 07:15:19 AM »

chmod(0777) maybe?  Huh
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC