mindblown Posted August 4, 2013 Share Posted August 4, 2013 Ok I have some code that's really starting to bug me... The form right under posts to a page and php picks it up and processes it. My problem is that the php will pick up the data and process it if the fields are not filled in or if only one but not both file input are selected. I want to be able to upload both at the same time.The other $POST variable post just fine but not when both $FILES are selected. P.s. I cleaned up the code a bit so its easier to read its not exactly how it is on my site please help! <form action="/administration/xxupload/" method="post" enctype="multipart/form-data"> <input type="hidden" name="artist_id" value="<?php echo $id; ?>" /> </span><input type="text" name="title" id="title" /> <span>Artwork:</span><input type="file" name="art" id="artwork"/> <span>Song:</span><input type="file" name="content" id="content"/> ><span>Details:</span><br/><textarea id="detail" name="detail" ></textarea> <input type="hidden" name="type" value="1" /> <input type="hidden" name="user" value="Admin" /> <input type="hidden" name="time" value="<?php echo time() ?>" /> <div id="tagsdiv">Tags:<input type="text" name="tags" /></div> <div id="submit"><input type="submit" name="upload_single"/></div> </form> Part of xxupload.php if (isset($_POST['upload_single'])){ $artist_id=$_POST['artist_id']; $artist_display=mysql_fetch_assoc(mysql_query("SELECT name FROM artists WHERE id=".$artist_id)); $artist_name=$artist_display['name']; $title=$_POST['title']; $tmp_art_name=$_FILES['art']['tmp_name']; $old_art_name=$_FILES['art']['name']; $dest_art="../media/singles/artwork/".$old_art_name; move_uploaded_file($tmp_art_name,$dest_art); $realart="../media/singles/artwork/".$artist_name."-".$title.".jpg"; $art="/media/singles/artwork/".$artist_name."-".$title.".jpg"; rename($dest_art,$realart); $tmp_content_name=$_FILES['content']['tmp_name']; $old_content_name=$_FILES['content']['name']; $dest_content="../media/singles/".$old_content_name; move_uploaded_file($tmp_content_name,$dest_content); $realcontent="../media/singles/".$artist_name."-".$title.".mp3"; $content="/media/singles/".$artist_name."-".$title.".mp3"; rename($dest_content,$realcontent); $detail=$_POST['detail']; $tags=$_POST['tags']; $type=$_POST['type']; $user=$_POST['user']; $tic=$_POST['time']; mysql_query ("INSERT INTO media(artist_id,title, art, content, detail,tags,user,type,tic) VALUES ('$artist_id','$title','$art','$content','$detail','$tags','$user','$type','$tic')"); header( 'Location: /administration/' ) ; } elseif Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted August 4, 2013 Share Posted August 4, 2013 a) you didn't state exactly what your code does when both files are chosen. stating it doesn't process them isn't specific enough as that doesn't tell us what execution path your code takes. what exactly does happen/what is the symptom when this occurs? b) your code doesn't have any logic in it to test if the upload worked before trying to use any of the uploaded file information. in programming, you must always test if a step that can fail has worked or not before using the data that you expected from that step. the size of the uploaded files is not under the control of your code, therefore they can be anything and since php limits both the size of each individual file and of the total amount of data sent from a form, you must test that there is form data to process before you attempt to use it. because php (tries to) abort the upload when you exceed the post_max_size setting, there is no $_POST or $_FILES data in this case and you should test if($_SERVER['REQUEST_METHOD'] == 'POST') to detect if an upload form was submitted. if all you want to do after that is make sure the file was uploaded, test if the error element is set and is equal to a zero if(isset($_FILES['art']['error']) && $_FILES['art']['error'] == 0){ code that uses the $_FILES['art'] data }. if you want to output a specific message for this case, you can test if the value in $_SERVER['CONTENT_LENGTH'] is greater than the post_max_size setting. if the total of all the files doesn't exceed the the post_max_size setting, but any individual file is still too large, the ['error'] element will be a 1 (see this link for all the upload error values - http://www.php.net/manual/en/features.file-upload.errors.php ). you can output specific error messages when any of these errors are detected to let the user know why their upload didn't work. Quote Link to comment Share on other sites More sharing options...
mindblown Posted August 4, 2013 Author Share Posted August 4, 2013 Yeah I'm sorry I guess i wasn't that clear in what i wanted to do. I'm trying to upload files to the server, one img and a mp3 file. Then rename and insert information about the uploaded files into a mysql database. I've since tried uploading smaller files and the script does work properly so now i know its a problem with the total size or individual sizes of the upload. I've changed a couple of things in php.ini file like the upload_max_filesize and the post_max_size but i doesnt seems to make a difference. Anyone know what i should change to get the file upload to function with larger files? Quote Link to comment Share on other sites More sharing options...
mindblown Posted August 4, 2013 Author Share Posted August 4, 2013 It has also given me this error too Warning: POST Content-Length of 8655354 bytes exceeds the limit of 8388608 bytes in Unknown on line 0 But I am not sure at all how to change that limit. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 5, 2013 Share Posted August 5, 2013 Re-read my last reply. Make a test and give us the result. Quote Link to comment Share on other sites More sharing options...
mindblown Posted August 12, 2013 Author Share Posted August 12, 2013 file count=0 array (size=0) empty I don't understand why that is happening Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 12, 2013 Share Posted August 12, 2013 Your script, please! Quote Link to comment Share on other sites More sharing options...
mindblown Posted August 12, 2013 Author Share Posted August 12, 2013 (edited) Hey sry I wanted to try a few more things before and I played around with some settings again in the php.ini file. It works now. I have to admit i don't know much about error reporting or about php.ini. Do you know of any videos or good articles that explain either? Edited August 12, 2013 by mindblown Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 13, 2013 Share Posted August 13, 2013 Do you know of any videos or good articles that explain either? As a web developer, you will often develop your scripts on unix (win) machines, web servers, database severs, ftp servers, mail servers and so on, so on. The best way for me and for everybody I guess is to start reading and understanding the error log files. Every web application above has a particular error directory on the real server. Go there, read the error message, if you don't understand it, go to the web site of this application or "google it" and try to find out what this error causes. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.