PHP uploading problem

Discussion in 'PHP' started by EliasJabb, Feb 9, 2008.

  1. #1
    Ok sorri for being a pain but i paid someone to make me a custom script for alot and got shit in return and fucked over.

    I will like it if someone can help me with this problem i have on my site customupload.com.

    Problem:
    Everything thats uploaded turns like this:
    http://www.customupload.com/uploads//52c57d9d48862cc79fed513bf7600f05jpg

    as u can see theres "//" after uploads :confused: and theres no "." before the type of image file in this case the jpg:confused:.

    heres the script:
    <?php
    /*
    
    - PHP4 Image upload script
    - coded by kreoton
    - downloaded from www.kreoton.net
    
    */
    
    class imageupload
    {
    	//pblic variables
    	var $path = '';
    	var $errorStr = '';
    	var $imgurl = '';
    
    	//private variables
    	var $_errors = array();
    	var $_params = array();
    	var $_lang = array();
    	var $_maxsize = 1048576;
    
    	var $_im_status = false;
    
    	//public methods
    	function imageupload ()
    	{
    		require 'config.php';
    		$this->_types = $types;
    		$this->_lang = $lang;
    		$this->_upload_dir = $upload_dir;
    		$this->_maxsize = $maxsize;
    
    		$this->path = $PHP_SELF;
    		
    		if (is_array($_FILES['__upload']))
    		{
    			$this->_params = $_FILES['__upload'];
    			if (function_exists('exif_imagetype'))
    				$this->_doSafeUpload();
    			else
    				$this->_doUpload();
    
    			if (count($this->_errors) > 0)
    				$this->_errorMsg();
    		}
    	}
    
    	function allowTypes ()
    	{
    		$str = '';
    		if (count($this->_types) > 0) {
    			$str = 'Allowed types: (';
    			$str .= implode(', ', $this->_types);
    			$str .= ')';
    		}
    
    		return $str;
    	}
    
    	// private methods
    	function _doSafeUpload ()
    	{
    		preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches);
    		if (exif_imagetype($this->_params['tmp_name']) && in_array(strtolower($matches[1]), $this->_types))
    		{
    			if ($this->_params['size'] > $this->_maxsize)
    				$this->_errors[] = $this->_lang['E_SIZE'];
    			else
    				$this->_im_status = true;
    
    			if ($this->_im_status == true)
    			{
    				$ext = substr($this->_params['name'], -4);
    				$this->new_name = md5(time()).$ext;
    
    				move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name);
                                    chmod($this->_upload_dir.$this->new_name, 0755);
    
    				$this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$this->_upload_dir.$this->new_name;
    			}
    		}
    		else
    			$this->_errors[] = $this->_lang['E_TYPE'];
    	}
    
    	function _doUpload ()
    	{
    		preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches);
    		if(in_array(strtolower($matches[1]), $this->_types))
    		{
    			if ($this->_params['size'] > $this->_maxsize)
    				$this->_errors[] = $this->_lang['E_SIZE'];
    			else
    				$this->_im_status = true;
    
    			if ($this->_im_status == true)
    			{
    				$ext = substr($this->_params['name'], -3);
    				$this->new_name = md5(time()).$ext;
    
    				move_uploaded_file($this->_params['tmp_name'], $this->_upload_dir.$this->new_name);
                                    chmod($this->_upload_dir.$this->new_name, 0755);
    
    				$this->imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$this->_upload_dir.'/'.$this->new_name;
    			}
    		}
    		else
    			$this->_errors[] = $this->_lang['E_TYPE'];
    	}
    
    	function _errorMsg()
    	{
    		$this->errorStr = implode('<br />', $this->_errors);
    	}
    }
    
    ?>
    PHP:
    IT WILL BE GREAT IF SOMEONE HELPED ME OUT I SPENT ALL MY MONEY ON THIS SCRIPT HOPING I CAN GET THE SITE RUNNING AND PEOPLE USIN IT :(
     
    EliasJabb, Feb 9, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    I'll fix one.

    Replace ...

    
    $this->new_name = md5(time()).$ext;
    
    PHP:
    With
    
    $this->new_name = md5(time()) . '.' . $ext;
    
    PHP:
    Jay
     
    jayshah, Feb 10, 2008 IP
  3. Alley Cat

    Alley Cat Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have a script which uploads images to my server, and submits details to database table. I also have a viewer based on similar script. The code for the Image Upload Script is;
    
    <?php
    $page_title = 'Upload a File';
    include ('includes/forms.html');
    $counter = 5;
    
    if (isset($_POST['submitted'])) {
    	require_once ('includes/mysql_connect.php');
    	
    	for ($i = 0; $i < $counter; $i++) {
    		
    		$path = '/uploads/';
    		$filename = 'upload' . $i;
    		$description = 'description' . $i;
    		$email = 'email' . $i;
    		
    		if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] != 4)) {
    		if (!empty($_POST[$email])) {
    			$e = "'" . escape_data($_POST[$email]) . "'";
    		} else {
    			$e = 'NULL';
    		}
    		
    		if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] != 4)) {
    		if (!empty($_POST[$description])) {
    			$d = "'" . escape_data($_POST[$description]) . "'";
    		} else {
    			$d = 'NULL';
    		}
    		
    		$query = "INSERT INTO uploads (email, file_path, file_name, file_size, file_type, description) VALUES ($e, $path, '{$_FILES[$filename]['name']}', '{$_FILES[$filename]['size']}', '{$_FILES[$filename]['type']}', $d)";
    		$result = mysql_query ($query);
    	
    	if ($result) {
    	
    		$upload_id = mysql_insert_id();
    		
    		if (move_uploaded_file($_FILES[$filename]['tmp_name'], "uploads/$upload_id")) {
    		echo '<p>File number ' . ($i + 1) . ' has been uploaded!</p>';
    	}  else {
    	
    		echo '<p>File number ' . ($i + 1) . ' could not be moved.</p>';
    		
    		$query = "DELETE FROM uploads WHERE upload_id = $upload_id";
    		$result = mysql_query ($query);
    	
    	}
    	
    } else {
    	echo '<p>Your submission could not be processed due to a system error.  We apologise for any inconvenience.</p>';
    }
    }
    }
    }
    mysql_close();
    }
    ?>
    <form enctype="multipart/form-data" action="add_file.php" method="post">
    <fieldset>
    <h3>File out the form to upload Your File(s):</h3>
    <input type="hidden" name="MAX_FILE_SIZE" value="524288" />
    <?php
    for ($i = 0; $i < $counter; $i++) {
    	echo '<p><b>Email Address:</b> <input type="text" name="email' . $i . '" size="40" maxlength="40" /></p>
    	<p><b>File:</b> <input type="file" name="upload' . $i . '" /></p>
    	<p><b>Description:</b> <textarea name="description' . $i . '" cols="40" rows="5"></textarea></p><br />
    	';
    	}
    	?>
    	
    	</fieldset>
    	<input type="hidden" name="submitted" value="TRUE" />
    	<div align="center"><input type="submit" name="submit" value="Submit" /></div>
    
    </form>
    <h3><a href="Screen_Saver.php">Screen Saver Order Form</a></h3>
    <?php
    include ('includes/foot.html');
    ?>
    
    Code (markup):
    Let me know if you would also like the image viewer script.
     
    Alley Cat, Feb 10, 2008 IP