Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ROXIT
    New Member
    • Apr 2013
    • 10

    Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty

    Hello Everyone please help me to sort out this warning..

    The below code is successfully running and all the data get successfully save into the database along with the photo which user uploads from registration form but when user doesn't uploads the photo then that time i am getting this warning....

    Warning: file_get_conten ts() [function.file-get-contents]: Filename cannot be empty in C:\xampp\htdocs \Project\123--login--test\New Login\formproce ss.php on line 114

    what i actually want is when a new user doesn't upload the photo then at that time the temporary photo should get save into the database along with their ID....

    guyz pls tell me what should i do......

    Code:
    <?php
    session_start();
    include('dbconnection.php');
    
    //Array to store validation errors
    	$errmsg_arr = array();
    	
    	//Validation error flag
    	$errflag = false;
    	
    	
    	//Select database
    	$db = mysql_select_db($db);
    	if(!$db) {
    		die("Unable to select database");
    	}
    
    /*********************************************************/
    
    //Function to sanitize values received from the form. Prevents SQL injection
    	function clean($str) {
    		$str = @trim($str);
    		if(get_magic_quotes_gpc()) {
    			$str = stripslashes($str);
    		}
    		return mysql_real_escape_string($str);
    	}
    	
    	//Sanitize the POST values
    	$fname = clean($_POST['fname']);
    	$lname = clean($_POST['lname']);
    	$uname = clean($_POST['uname']);
    	$password = clean($_POST['password']);
    	$cpassword = clean($_POST['cpassword']);
    	
    	//Input Validations
    	if($fname == '') {
    		$errmsg_arr[] = 'First name missing';
    		$errflag = true;
    	}
    	if($lname == '') {
    		$errmsg_arr[] = 'Last name missing';
    		$errflag = true;
    	}
    	if($uname == '') {
    		$errmsg_arr[] = 'User Name missing';
    		$errflag = true;
    	}
    	if($password == '') {
    		$errmsg_arr[] = 'Password missing';
    		$errflag = true;
    	}
    	if($cpassword == '') {
    		$errmsg_arr[] = 'Confirm password missing';
    		$errflag = true;
    	}
    	if( strcmp($password, $cpassword) != 0 ) {
    		$errmsg_arr[] = 'Passwords do not match';
    		$errflag = true;
    	}
    		//Check for duplicate login ID
    	if($uname != '')
    	{
    		$qry = "SELECT * FROM home WHERE uname='$uname'";
    		$result = mysql_query($qry);
    		if($result) 
    		{
    			if(mysql_num_rows($result) > 0) 
    			{
    				$errmsg_arr[] = 'UserName already in use';
    				$errflag = true;
    			}
    			@mysql_free_result($result);
    		}
    		else {
    			die("Query failed");
    		}
    	}
    	
    	//If there are input validations, redirect back to the registration form
    	if($errflag) {
    		$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
    		session_write_close();
    		header("location: welcomeadmin.php");
    		exit();
    	}
    
    /*$qry1= "Insert into home (id ,name ,venue ,date ,organizer )
    					values ('', '$_POST[name]', '$_POST[venue]', '$_POST[date]', '$_POST[organizer]')";*/
    
    	//echo $qry1;
    	$qry1= "Insert into home (id ,fname ,lname ,uname ,password )
    					values ('', '$_POST[fname]', '$_POST[lname]', '$_POST[uname]', '".md5($_POST['password'])."')";
    
    	if (!mysql_query($qry1,$con))
    	{
    		die('Error: ' . mysql_error());
    	}
    	else
    	{
    		echo "<br>1 record added";
    	}
    /********************************************************/
    if($_FILES['photo']['tmp_name'] || $name = $_FILES['photo']['name'] || $_FILES['photo']['size'] || $_FILES['photo']['type'] == 0 )
    {
    	
    // Below I am Getting Problem 
    
    		$path = $_FILES['photo']['xyz'];
    		$name = $_FILES['photo']['181073_539601282751625_1917748691_n.jpg'];
    		$size = $_FILES['photo']['28895'];
    		$type = $_FILES['photo']['image/jpeg'];
    /*Here*/	$content = file_get_contents($path);
    		
    		
    //		if ($conn = mysqli_connect('localhost', 'root', '', 'maahole_db'))
    		
    		if($conn = mysqli_connect('localhost', 'root', '', 'newlogin'))
    		{
    			$content = mysqli_real_escape_string($conn, $content);			
    			
    			$sql="insert into homeimage (id, name, size, type, content) 
    					values('', '{$name}', '{$size}', '{$type}', '{$content}') ";
    					
    					
    			
    					
    			if (mysqli_query($conn, $sql))
    			{
    				$uploadOk = true;
    				$imageId = mysqli_insert_id($conn);
    				echo $imageId;
    				echo "Success";
    			}
    			else 
    			{
    				echo "Error: Could not save the data to mysql database. Please try again.".mysql_error();
    			}
    		
    			mysqli_close($conn);
    		}
    		else
    		{
    			echo "Error: Could not connect to mysql database. Please try again.";
    		}
    	
    }
    else{
    		$path = $_FILES['photo']['tmp_name'];
    		$name = $_FILES['photo']['name'];
    		$size = $_FILES['photo']['size'];
    		$type = $_FILES['photo']['type'];
    		$content = file_get_contents($path);
    		
    		
    //		if ($conn = mysqli_connect('localhost', 'root', '', 'maahole_db'))
    		
    		if($conn = mysqli_connect('localhost', 'root', '', 'newlogin'))
    		{
    			$content = mysqli_real_escape_string($conn, $content);			
    			
    			$sql="insert into homeimage (id, name, size, type, content) 
    					values('', '{$name}', '{$size}', '{$type}', '{$content}') ";
    					
    					
    			
    					
    			if (mysqli_query($conn, $sql))
    			{
    				$uploadOk = true;
    				$imageId = mysqli_insert_id($conn);
    				echo $imageId;
    				echo "Success";
    			}
    			else 
    			{
    				echo "Error: Could not save the data to mysql database. Please try again.".mysql_error();
    			}
    		
    			mysqli_close($conn);
    		}
    		else
    		{
    			echo "Error: Could not connect to mysql database. Please try again.";
    		}
    	
    }
    		
    ?>
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    That's because the file path is empty. You should check if it's empty first before trying to get the contents.

    Comment

    Working...