473,385 Members | 1,528 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 1198
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: 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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.