473,385 Members | 1,942 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.

In my code, .mp3 files fail to upload but image files are uploading. What am I doing

1
I wrote this code for a file(audio) upload application, but whenever I add a music file to the file input it shows "Notice: Undefined variable: theFIle". However, when I upload image files instead it works perfectly:

Here's the code below:
Expand|Select|Wrap|Line Numbers
  1.     <?php
  2.  
  3. $db_name = "745";
  4. $db_user = "root";
  5. $db_host = "localhost";
  6. $db_password = "";
  7.  
  8.  
  9.  
  10. $mysqli = new mysqli('localhost','root','','745');
  11. echo "<br>Connected<br>";
  12.  
  13. if($mysqli->connect_error){
  14.   die('Connection Error: ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
  15. }
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.   if(isset($_POST['upload'])){
  23.  
  24.   $artist = $_POST["artist"];
  25.   $song = $_POST["song"];
  26.   $theFile = ($_FILES["filename"]["name"]);
  27.   $uploadDir = "myDir1/";
  28.   $uploadDir = $uploadDir.basename($_FILES["filename"]["name"]);
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  $sql = $mysqli->query("INSERT INTO music1 (id, artiste, song, file) VALUES (id, '$artist', '$song', '$uploadDir')");
  35.     echo "<br> INSERTED ".$uploadDir;
  36.  
  37.  if (move_uploaded_file($_FILES["filename"]["tmp_name"],$uploadDir)){
  38.       echo "<br>file ".$_FILES['filename']['name']." uploaded to ".$uploadDir."<br>";
  39.     }else{echo $_FILES['filename']['name']." not uploaded <br>";}
  40.  
  41.   }else{echo "<br>Wrong file type: only images allowed<br>";}
  42.  
  43.  
  44.  $dir = "myDir";
  45. // I use this line below for testing: to check test.txt if name of the file is captured properly. [It always is...in all cases except .mp3. :( ]
  46. file_put_contents($dir."/test.txt",$theFile);
  47.  
  48.     ?>
  49.  
Oct 18 '14 #1
1 1199
Luuk
1,047 Expert 1GB
- you fail to give the 'exact' error message. this way a reader here can only guess what might be wrong.
- you fail to use the '[code]' tags

Did you read the user notes on this page: http://php.net/manual/en/function.mo...oaded-file.php ?
Oct 18 '14 #2

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

Similar topics

1
by: Stijn Goris | last post by:
hi all, A user can upload maximum 10 image files at once. When the user only uploads 6 images, 4 fileboxes are left blank. I use function checkImage() //check the the extension. Must be a jpeg...
0
by: dermoon | last post by:
Made this simple cgi-upload script that uses fieldstorage from a web-form. ASCII-based files works fine, but if i try to upload binary-files (word-documents, images) the files seems to be truncated...
1
by: TK | last post by:
I have a file upload control to allow a user to select/upload a file to the server. They need to upload x number of files in one shot because they have to confirm that they are uploading x number...
2
by: Ryan Moore | last post by:
I am creating a site that has an "Uploads" directory where users can upload image files (let's say .jpgs and .gifs). When a user uploads an image, the system creates a directory within this...
2
by: G | last post by:
Hello Friend, I am handling a module using ASP3.0 which has to upload an movie clipsof size 1 mb or 2 mb. i have a code which upload only files or images. So I need your help for this. If you...
2
by: bsdanielm | last post by:
Hello folks, How do I go about implementing an upload function so that images/photos can be uploaded into an SQL database??? Any help / Advice would be great
7
by: xx75vulcan | last post by:
Hi, I've got a PHP Upload Form that works great, unless that is, the image your uploading has been modified through a photo editing software. Example: if I upload the image straight from a...
1
by: helplakshmi | last post by:
Hi All, I wish you a Happy new year!!!.. My requirement is to upload an excel file using PHP and to update the data in MSSQL. For which i have designed a screen so that the user can browse 2...
1
by: rick shade | last post by:
I'm not able to get code to display my image files: //not working, no image, just blank space echo " <td><a href='../images/{$row}' border='0' class='myImage'> <img...
2
by: sidhx | last post by:
how can i let image overwriting when uploading? and if uploading an image say "logo.jpg" and if a file already existing say "logo.png" then, how can i replace the file logo.png to logo.jpg(which has...
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: 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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.