dandan321 Posted July 29, 2007 Share Posted July 29, 2007 Hello, I am having trouble with getting my uploader script to do what I need it to do. The uploader works fine. What I am trying to do is give an option to upload or not to upload. (this way if an image is present in the database, users would have a choice to upload or not.) I have two parts of code, html and php Any help in this would be great! HTML <html> <head></head> <body> <form action="test.php" method="post" enctype="multipart/form-data"> <br><br> Choose a file to upload:<br> <input type="file" name="file"><br> <input name="filec" type="checkbox" value="check" checked> Yes I want to upload a file<br> <input type="submit" name="submit" value="submit"> </form> </body> </html> PHP <?php if ($HTTP_POST_VARS['submit']) { if ($HTTP_POST_VARS['filec'] != "check") { Header("Location: http://www.yahoo.com"); } else { if (!is_uploaded_file($HTTP_POST_FILES['file']['tmp_name'])) { $error = "You did not upload a file!"; unlink($HTTP_POST_FILES['file']['tmp_name']); // assign error message, remove uploaded file, redisplay form. Header("Location: somepage.php?error=" . $error); } else { //a file was uploaded $maxfilesize=20000000; if ($HTTP_POST_FILES['file']['size'] > $maxfilesize) { $error = "file is too large"; unlink($HTTP_POST_FILES['file']['tmp_name']); // assign error message, remove uploaded file, redisplay form. Header("Location: somepage.php?error=" . $error); } else { if ($HTTP_POST_FILES['file']['type'] != "image/gif" AND $HTTP_POST_FILES['file']['type'] != "image/pjpeg") { $error = "This file type is not allowed"; Header("Location: somepage.php?error=" . $error); unlink($HTTP_POST_FILES['file']['tmp_name']); //assign error message, remove uploaded file, redisplay form. } else { //File has passed all validation, copy it to the final destination and remove the temporary file: copy($HTTP_POST_FILES['file']['tmp_name'],"/hshome/martinar/martinarts.org/test/files/".$HTTP_POST_FILES['file']['name']); unlink($HTTP_POST_FILES['file']['tmp_name']); //print "File has been successfully uploaded!"; Header("Location: somepage.php?file=" . $HTTP_POST_FILES['file']['name'] . "&type=" . $HTTP_POST_FILES['file']['type']); exit; } } } } } ?> Quote Link to comment Share on other sites More sharing options...
Humpty Posted July 29, 2007 Share Posted July 29, 2007 Just as a sugestion until someone who knows what they are doing can answer, I would like point out that the file starts to upload when you submit. Perhaps if the EU doesn't want to upload a picture hide that file input using JS or on the second script maybe set the file size to 2bytes or something. (Sorry if i didn't understand the problem) Quote Link to comment Share on other sites More sharing options...
dandan321 Posted July 30, 2007 Author Share Posted July 30, 2007 Thanks for the reply, Though the problem I am having is that when the page is submitted its not reading the conditional code. If they check yes I want to upload, it should upload and if they uncheck it, the conditional code should take them to another page bypassing the upload. I want to see if my code is right. Dan Quote Link to comment Share on other sites More sharing options...
dandan321 Posted July 30, 2007 Author Share Posted July 30, 2007 I figured it out. I am new to php. every time I was putting in = it was bypassing the if statement. What I needed to put in was == This script works but its backwords because its using non equal to != I put the != in right before I submitted the post. Dan Quote Link to comment Share on other sites More sharing options...
Humpty Posted July 30, 2007 Share Posted July 30, 2007 well that will teach me for concocting my onw conclusions (Humpty World is a nice world) 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.