- This topic is empty.
-
AuthorPosts
-
August 7, 2014 at 4:46 pm #178192
MBM
ParticipantI have adapted a script I use to upload images into a folder to upload audio but audio files do not save – neither the path into the table or the audio into the folder. Is getimagesize the problem because I need to check other formats?
<?php include "connect.php"; require "authenticate.php"; error_reporting(E_ERROR); $message = $_GET['message']; //function to check for valid image formats function uploadfile($dir){ if(!empty($_FILES)){ $url =''; $file = getimagesize($_FILES["file"]["tmp_name"]); $allowedExts = array("gif", "jpeg", "jpg", "png", "JPG", "JPEG", "PNG", "GIF", "mp3"); $temp = explode(".", $_FILES["file"]["name"]); $extension = end($temp); if ((($file["mime"] == "image/gif") || ($file["mime"] == "image/jpeg") || ($file["mime"] == "image/jpg") || ($file["mime"] == "image/pjpeg") || ($file["mime"] == "image/x-png") || ($file["mime"] == "image/png") || ($file["mime"] == "audio/mp3") ) && ($_FILES["file"]["size"] < 2000000) && in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; } else { $path = $dir . $_FILES["file"]["name"]; { move_uploaded_file($_FILES["file"]["tmp_name"], $dir . $_FILES["file"]["name"]); $path = $dir . $_FILES["file"]["name"]; } } } else { $message = "Wrong format"; } } return $path; }
August 7, 2014 at 5:23 pm #178200chrisburton
ParticipantIs getimagesize the problem because I need to check other formats?
Probably. It should return false. Did you check?
August 7, 2014 at 5:26 pm #178203MBM
ParticipantIt doesn’t return false. I’m not sure how to change the code to check all formats.
August 7, 2014 at 5:31 pm #178204chrisburton
ParticipantInstead of
getimagesize
, tryFILEINFO_MIME_TYPE
August 7, 2014 at 5:47 pm #178209MBM
ParticipantI tried :
$file = FILEINFO_MIME_TYPE($_FILES["file"]["tmp_name"]);
Call to undefined function FILEINFO_MIME_TYPE()
Then added :
define('FILEINFO_MIME_TYPE', 16);
Same error.
August 7, 2014 at 5:50 pm #178210chrisburton
Participant@MBM What version of PHP are you running?
Try
FILEINFO_MIME
, first. If that doesn’t work trymime_content_type
. Although I would recommend upgrading.August 7, 2014 at 5:55 pm #178211MBM
Participant5.3. FILEINFO_MIME gave the same problem.
August 7, 2014 at 5:59 pm #178212chrisburton
Participant@MBM Where are you developing this? Locally? Live server?
August 7, 2014 at 6:41 pm #178214MBM
ParticipantIt’s live. I have a website for creating trading cards – form and image data.
http://thetradingcardgenerator.com
I’m trying to adapt the code so I can upload other data formats for another website but am testing it on my server.
August 7, 2014 at 8:05 pm #178218chrisburton
Participant@MBM Do you have access to the php.ini file?
August 7, 2014 at 8:20 pm #178219MBM
ParticipantThe code is correct and there’s an issue at the server end?
register_globals = off allow_url_fopen = off expose_php = Off max_input_time = 60 variables_order = "EGPCS" extension_dir = ./ upload_tmp_dir = /tmp precision = 12 SMTP = ****** url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset=" ; Only uncomment zend optimizer lines if your application requires Zend Optimizer support ; -- Be very careful to not to disable a function which might be needed! ; -- Uncomment the following lines to increase the security of your PHP site. ;disable_functions = "highlight_file,ini_alter,ini_restore,openlog,passthru, ; phpinfo, exec, system, dl, fsockopen, set_time_limit, ; popen, proc_open, proc_nice,shell_exec,show_source,symlink"
August 7, 2014 at 8:48 pm #178221chrisburton
ParticipantThe code is correct and there’s an issue at the server end?
How is the code correct if it’s not working?
August 7, 2014 at 8:49 pm #178222MBM
ParticipantSorry I thought you were suggesting the problem was server side and not the code itself.
August 7, 2014 at 8:54 pm #178223chrisburton
ParticipantPHP is server side. Anyway, you said the code you are working on is on a live server and not locally (Xamp, Mamp, Wamp), correct?
August 7, 2014 at 9:04 pm #178224MBM
ParticipantNo. I’m testing live. I don’t need to test locally. Image upload works. MP3 does not.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.