473,385 Members | 1,375 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,385 software developers and data experts.

Warning: file_get_contents(): Filename cannot be empty

5
Hi I would like to point out before I get into this that I am a PHP newb, and I have been struggling for a while. I'm trying this new script, but I got an error every time I did upload file.

Warning: file_get_contents(): Filename cannot be empty in C:\Users\user\Desktop\xampp\htdocs\ubfm\d2.php on line 18

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Check if a file has been uploaded
  3. if(isset($_FILES['uploaded_file'])) {
  4.     // Make sure the file was sent without errors
  5.     {
  6.         // Connect to the database
  7.         $dbLink = new mysqli('localhost', 'root', '', 'upload');
  8.         if(mysqli_connect_error()) {
  9.             die("MySQL connection failed: ". mysqli_connect_error());
  10.         }
  11. // Gather all required data
  12. $name = &$_POST['name']; 
  13. $email = &$_POST['email']; 
  14. $subject = &$_POST['subject'];
  15. $department = &$_POST['department'];
  16. $message = &$_POST['message'];
  17. $mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
  18. $data = $dbLink->real_escape_string(file_get_contents($_FILES['uploaded_file']['tmp_name']));
  19. $size = intval($_FILES['uploaded_file']['size']);
  20.  
  21.  
  22.         // Create the SQL query
  23.         $query = "
  24.             INSERT INTO `file`(Name,email,subject,department,message,mime,size,data,created)
  25.             VALUES('$name','$email','$subject','$department','$message','$mime',$size,'$data', NOW()
  26.             )";
  27.  
  28.         // Execute the query
  29.         $result = $dbLink->query($query);
  30.  
  31.         // Check if it was successfull
  32.         if($result) {
  33.             echo 'Success! Your file was successfully added!';
  34.         }
  35.         else {
  36.             echo 'Error! Failed to insert the file'
  37.                . "<pre>{$dbLink->error}</pre>";
  38.         }
  39.     }
  40.  
  41.  
  42. }
  43. else {
  44.     echo 'Error! A file was not sent!';
  45. }
  46.  
  47. // Echo a link back to the main page
  48. echo '<p>Click <a href="d1.php">here</a> to go back</p>';
  49. ?>
Oct 22 '14 #1
2 4768
iam_clint
1,208 Expert 1GB
Is your file input named uploaded_files?
Oct 22 '14 #2
rian92
5
Hi iam_clint,
Yes that my input name.
Oct 26 '14 #3

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

Similar topics

0
by: Auday Alwash | last post by:
Hi, A month ago, we were running out of disk space on a drive that stores the data file for a SQL Server 7 database. So I added a new drive and created a new data file on the primary filegroup...
18
by: Tjerk Wolterink | last post by:
i have the following rule, <xsl:template match="br"> <br/> </xsl:template> This should convert all <br/> to <br/> but, my transformer transforms it all to
2
by: Nahappan SM | last post by:
I have a struct : #include <string> struct __declspec (dllexport) FILEPROPERTIES { std::wstring FileName; std::wstring Type; };
2
by: Jack Addington | last post by:
I have created an event and delegate combination for use in a user control when I place it on a form. However because I'm not actually doing anything in the event in the user object I didn't...
0
by: Steve Franks | last post by:
Every time I rebuild my ASP.NET site (2005 beta 2) I get the following warning, and I cannot figure out where it is coming from and how to resolve it: Warning 1 The type 'myquicktest' in...
0
by: Rob R. Ainscough | last post by:
When I run my Test application I get the following error: Warning: The dependency 'MyCompany.Utilities, Version=1.0.1852.27525, Culture=neutral' in project 'MyCompany.Remote' cannot be copied to...
0
by: Edge1960 | last post by:
I am using Visual Web Developer along with SQLExpress on a WinXP Pro 2002 SP2 machine with a 3.79 GHz processor with 2GB of RAM to create a web application for entering data to a database. I am...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
8
by: thatcollegeguy | last post by:
http://smarterfootball.com/exits/theHTML.html I am not sure what is wrong w/ this code. The main issue is that the table that is in the initial html will empty its td but the table that I load...
1
by: ROXIT | last post by:
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...
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
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.