daebat Posted January 6, 2010 Share Posted January 6, 2010 So I've been trying to crank this out for a while now. I have gotten to the point where it stores the title but my file upload and storage of the name aren't working. This is a really rough version so don't be too harsh FORM: <form method="post" action="upload_process.php" enctype="multipart/form-data"> <p> Title: </p> <input type="text" name="title"/> <p> Thumbnail: </p> <input type="file" name="thumb"> <p> EPS 1: </p> <input type="file" name="eps1"> <p> EPS 2: </p> <input type="file" name="eps2"> <p> PDF 1: </p> <input type="file" name="pdf1"> <p> PDF 2: </p> <input type="file" name="pdf2"> <br/> <br/> <input TYPE="submit" name="upload" title="Add data to the Database" value="Submit"/> </form> PHP: <?php $target = "path/to/upload/"; $target = $target . basename( $_FILES['thumb']['thumbName']['eps1']['eps1Name']['eps2']['eps2Name']['pdf1']['pdf1Name']['pdf2']['pdf2Name']); $title=$_POST['title']; $thumb=($_FILES['thumb']['thumbName']); $eps1=($_FILES['eps1']['eps1Name']); $eps2=($_FILES['eps2']['eps2Name']); $pdf1=($_FILES['pdf1']['pdf1Name']); $pdf2=($_FILES['pdf2']['pdf2Name']); mysql_connect("localhost", "user", "pass") or die(mysql_error()) ; mysql_select_db("table") or die(mysql_error()) ; mysql_query("INSERT INTO test (title,thumb,eps1,eps2,pdf1,pdf2) VALUES ('$title', '$thumb', '$eps1', '$eps2', '$pdf1','$pdf2')") ; if(move_uploaded_file($_FILES['thumb']['tmp_name']['eps1']['tmp_name']['eps2']['tmp_name']['pdf1']['tmp_name']['pdf2']['tmp_name'], $target)) { echo "The files ". basename( $_FILES['uploadedfile']['thumbname']['eps1Name']['eps2Name']['pdf1Name']['pdf2Name']). " have been uploaded, and your information has been added to the directory"; } else { echo "Sorry, there was a problem uploading your file."; } ?> Thanks in advance, -Chad Quote Link to comment https://forums.phpfreaks.com/topic/187424-form-submission/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 6, 2010 Share Posted January 6, 2010 You need to start by looking at what the $_FILES array actually contains and making your logic match it. Add the following php code near the start of your form processing code - echo "<pre>"; echo "FILES:"; print_r($_FILES); echo "</pre>"; You should also be learning php (or learning anything new in php), developing php code, and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that php will help you by displaying all errors it finds. Stop and start your server to get any changes made to php.ini to take effect and confirm that the actual settings get changed by using a phpinfo() statement in case the php.ini that you are changing is not the one that php is using. Quote Link to comment https://forums.phpfreaks.com/topic/187424-form-submission/#findComment-989742 Share on other sites More sharing options...
daebat Posted January 6, 2010 Author Share Posted January 6, 2010 Ok thanks. I added that code and it tells me all about the files I am attempting to upload. Obviously it is telling me that it failed. I am using Zend Development platform so I see the errors, I just don't know how to fix them. It's saying that I have an Undefined Index for all of my uploads. To tell you the truth I am attempting to modify a script from a guy that had set this up to upload one photo, store it, as well as some other data. Unfortunately I feel like I have hacked the script to hell and don't even know where to begin with fixing the logic. Quote Link to comment https://forums.phpfreaks.com/topic/187424-form-submission/#findComment-989746 Share on other sites More sharing options...
PFMaBiSmAd Posted January 6, 2010 Share Posted January 6, 2010 Obviously it is telling me that it failed. Only if the ['error'] elements (i.e. $_FILES['thumb']['error'] ) are non-zero values. If you look closely at the output from the print_r() statement, you will see that the correct variables are things like - $_FILES['thumb']['name'], $_FILES['eps1']['name'], ... Quote Link to comment https://forums.phpfreaks.com/topic/187424-form-submission/#findComment-989752 Share on other sites More sharing options...
daebat Posted January 6, 2010 Author Share Posted January 6, 2010 I'm confused. It is giving me [error] => 0 for all of the form fields. Does that mean there is no error? Quote Link to comment https://forums.phpfreaks.com/topic/187424-form-submission/#findComment-989762 Share on other sites More sharing options...
PFMaBiSmAd Posted January 6, 2010 Share Posted January 6, 2010 Yes - http://us3.php.net/manual/pl/features.file-upload.errors.php Quote Link to comment https://forums.phpfreaks.com/topic/187424-form-submission/#findComment-989780 Share on other sites More sharing options...
daebat Posted January 6, 2010 Author Share Posted January 6, 2010 OK well then why don't the files show up in the upload folder? and why doesn't the name reference to the database? I understand that I may have set it up wrong but I need to know what to change in order to learn what I did wrong. I'm going to be using this as a sort of template to build several other upload forms. If I can just get this one right I will be home free! Quote Link to comment https://forums.phpfreaks.com/topic/187424-form-submission/#findComment-989784 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.