473,382 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

10
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_contents() [function.file-get-contents]: Filename cannot be empty in C:\xampp\htdocs\Project\123--login--test\New Login\formprocess.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......

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. session_start();
  4. include('dbconnection.php');
  5.  
  6. //Array to store validation errors
  7.     $errmsg_arr = array();
  8.  
  9.     //Validation error flag
  10.     $errflag = false;
  11.  
  12.  
  13.     //Select database
  14.     $db = mysql_select_db($db);
  15.     if(!$db) {
  16.         die("Unable to select database");
  17.     }
  18.  
  19. /*********************************************************/
  20.  
  21. //Function to sanitize values received from the form. Prevents SQL injection
  22.     function clean($str) {
  23.         $str = @trim($str);
  24.         if(get_magic_quotes_gpc()) {
  25.             $str = stripslashes($str);
  26.         }
  27.         return mysql_real_escape_string($str);
  28.     }
  29.  
  30.     //Sanitize the POST values
  31.     $fname = clean($_POST['fname']);
  32.     $lname = clean($_POST['lname']);
  33.     $uname = clean($_POST['uname']);
  34.     $password = clean($_POST['password']);
  35.     $cpassword = clean($_POST['cpassword']);
  36.  
  37.     //Input Validations
  38.     if($fname == '') {
  39.         $errmsg_arr[] = 'First name missing';
  40.         $errflag = true;
  41.     }
  42.     if($lname == '') {
  43.         $errmsg_arr[] = 'Last name missing';
  44.         $errflag = true;
  45.     }
  46.     if($uname == '') {
  47.         $errmsg_arr[] = 'User Name missing';
  48.         $errflag = true;
  49.     }
  50.     if($password == '') {
  51.         $errmsg_arr[] = 'Password missing';
  52.         $errflag = true;
  53.     }
  54.     if($cpassword == '') {
  55.         $errmsg_arr[] = 'Confirm password missing';
  56.         $errflag = true;
  57.     }
  58.     if( strcmp($password, $cpassword) != 0 ) {
  59.         $errmsg_arr[] = 'Passwords do not match';
  60.         $errflag = true;
  61.     }
  62.         //Check for duplicate login ID
  63.     if($uname != '')
  64.     {
  65.         $qry = "SELECT * FROM home WHERE uname='$uname'";
  66.         $result = mysql_query($qry);
  67.         if($result) 
  68.         {
  69.             if(mysql_num_rows($result) > 0) 
  70.             {
  71.                 $errmsg_arr[] = 'UserName already in use';
  72.                 $errflag = true;
  73.             }
  74.             @mysql_free_result($result);
  75.         }
  76.         else {
  77.             die("Query failed");
  78.         }
  79.     }
  80.  
  81.     //If there are input validations, redirect back to the registration form
  82.     if($errflag) {
  83.         $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  84.         session_write_close();
  85.         header("location: welcomeadmin.php");
  86.         exit();
  87.     }
  88.  
  89. /*$qry1= "Insert into home (id ,name ,venue ,date ,organizer )
  90.                     values ('', '$_POST[name]', '$_POST[venue]', '$_POST[date]', '$_POST[organizer]')";*/
  91.  
  92.     //echo $qry1;
  93.     $qry1= "Insert into home (id ,fname ,lname ,uname ,password )
  94.                     values ('', '$_POST[fname]', '$_POST[lname]', '$_POST[uname]', '".md5($_POST['password'])."')";
  95.  
  96.     if (!mysql_query($qry1,$con))
  97.     {
  98.         die('Error: ' . mysql_error());
  99.     }
  100.     else
  101.     {
  102.         echo "<br>1 record added";
  103.     }
  104. /********************************************************/
  105. if($_FILES['photo']['tmp_name'] || $name = $_FILES['photo']['name'] || $_FILES['photo']['size'] || $_FILES['photo']['type'] == 0 )
  106. {
  107.  
  108. // Below I am Getting Problem 
  109.  
  110.         $path = $_FILES['photo']['xyz'];
  111.         $name = $_FILES['photo']['181073_539601282751625_1917748691_n.jpg'];
  112.         $size = $_FILES['photo']['28895'];
  113.         $type = $_FILES['photo']['image/jpeg'];
  114. /*Here*/    $content = file_get_contents($path);
  115.  
  116.  
  117. //        if ($conn = mysqli_connect('localhost', 'root', '', 'maahole_db'))
  118.  
  119.         if($conn = mysqli_connect('localhost', 'root', '', 'newlogin'))
  120.         {
  121.             $content = mysqli_real_escape_string($conn, $content);            
  122.  
  123.             $sql="insert into homeimage (id, name, size, type, content) 
  124.                     values('', '{$name}', '{$size}', '{$type}', '{$content}') ";
  125.  
  126.  
  127.  
  128.  
  129.             if (mysqli_query($conn, $sql))
  130.             {
  131.                 $uploadOk = true;
  132.                 $imageId = mysqli_insert_id($conn);
  133.                 echo $imageId;
  134.                 echo "Success";
  135.             }
  136.             else 
  137.             {
  138.                 echo "Error: Could not save the data to mysql database. Please try again.".mysql_error();
  139.             }
  140.  
  141.             mysqli_close($conn);
  142.         }
  143.         else
  144.         {
  145.             echo "Error: Could not connect to mysql database. Please try again.";
  146.         }
  147.  
  148. }
  149. else{
  150.         $path = $_FILES['photo']['tmp_name'];
  151.         $name = $_FILES['photo']['name'];
  152.         $size = $_FILES['photo']['size'];
  153.         $type = $_FILES['photo']['type'];
  154.         $content = file_get_contents($path);
  155.  
  156.  
  157. //        if ($conn = mysqli_connect('localhost', 'root', '', 'maahole_db'))
  158.  
  159.         if($conn = mysqli_connect('localhost', 'root', '', 'newlogin'))
  160.         {
  161.             $content = mysqli_real_escape_string($conn, $content);            
  162.  
  163.             $sql="insert into homeimage (id, name, size, type, content) 
  164.                     values('', '{$name}', '{$size}', '{$type}', '{$content}') ";
  165.  
  166.  
  167.  
  168.  
  169.             if (mysqli_query($conn, $sql))
  170.             {
  171.                 $uploadOk = true;
  172.                 $imageId = mysqli_insert_id($conn);
  173.                 echo $imageId;
  174.                 echo "Success";
  175.             }
  176.             else 
  177.             {
  178.                 echo "Error: Could not save the data to mysql database. Please try again.".mysql_error();
  179.             }
  180.  
  181.             mysqli_close($conn);
  182.         }
  183.         else
  184.         {
  185.             echo "Error: Could not connect to mysql database. Please try again.";
  186.         }
  187.  
  188. }
  189.  
  190. ?>
  191.  
  192.  
May 13 '13 #1
1 9731
Rabbit
12,516 Expert Mod 8TB
That's because the file path is empty. You should check if it's empty first before trying to get the contents.
May 13 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ryan | last post by:
My project uses the /ORDER specifier to order functions as specified in file containing the decorated names of packaged functions (COMDATs). I am in the process of upgrading from VC6 to VC.NET 2003....
1
usafshah
by: usafshah | last post by:
Warning: in_array() : Wrong datatype for second argument in \tickets\functions_ticketsui.php on line 196 Can Any one tell me what this warning means ?
3
by: mrosado | last post by:
Hi everybody, I have this problem.- The browser launch this two errors: Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at...
1
by: servo | last post by:
I created a user "test1" (which then got the username "debscrof_test1" from CPanel), a password for the user "test2", and then added the user to a new database "testdb" with all priviliges Then a...
2
by: sanjusb | last post by:
My problem is : Warning: session_start() : Cannot send session cookie - headers already sent by (output started at /home/xtreme/public_html/forum_tire.php:2) in...
0
by: smokenlinks | last post by:
I am working on a script and i get this error Warning: fsockopen() : unable to connect to https://www.alertpay.com:443 (Unable to find the socket transport "https" - did you forget to enable it...
5
by: lisles | last post by:
i have a page funtion.php which hs the function to connect to the db /* Mysql Connection */ function connect(){ global $db_server,$db_user,$db_pass,$db;//Global Values from the config.php...
1
by: lisa007 | last post by:
Warning: mail() : SMTP server response: 503 valid RCPT command must precede DATA on whenever user click on to get new password but doesnt fill in the username field it shows that message i have...
2
by: pradeep28march | last post by:
function createSaveJPGThumb($filename, $uploadfile, $newwidth, $quality = 80){ //resize image to max 800 wide list($width, $height) = getimagesize($filename); $newheight = $height *...
1
by: ivan bravo | last post by:
Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at C:\Inetpub\wwwroot\pum\commons\Session.Commons.mod ule.php:7) in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.