Scud Posted October 7, 2011 Share Posted October 7, 2011 I am currently using a form for uploading resumes. <?php $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } /* this part can either be in the same file as the form or it can be in a different file. If you want this in a different file, make the "action" of the form go to that file */ if(sizeof($_POST)) { $body = ""; while(list($key, $val) = each($HTTP_POST_VARS)) { $body .= "$key: $val \n"; } mail("xx@xx.com", // to "Resume", $body, "From:".$Email); } // end form processing ?> I am hoping that if no file is uploaded it skips the upload process and just sends the email. Also how can i make it so when the file is uploaded it is renamed to "Resume - Users first and last name" Thanks Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted October 7, 2011 Share Posted October 7, 2011 1. to check if a file has been uploaded.. if(!empty($_FILE)){ //proceed with code } 2. to change the file name, change the $target variable $target = upload/whateverfilenameyouwant.jpg just make sure that you get the extension right, make it dynamic based on what the extension is for $_FILE['uploaded']['name'] Quote Link to comment Share on other sites More sharing options...
Scud Posted October 8, 2011 Author Share Posted October 8, 2011 I am not too experienced in Php, how can i do this so when no file is uploaded rather then running the script and stating there is an error in the upload it simply just email's the remainder of the form? However when a file has been selected it runs the upload script? If an attachment is uploaded is it possible to send a link to the attachment in the email? also is there any way to make the uploaded file name the name the user entered in one of the input boxes? Quote Link to comment Share on other sites More sharing options...
Mancent Posted October 8, 2011 Share Posted October 8, 2011 <?php if(!empty($_FILE)){ $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } } is correct just add that to the top of the script and then do a else else { //the email system /* this part can either be in the same file as the form or it can be in a different file. If you want this in a different file, make the "action" of the form go to that file */ if(sizeof($_POST)) { $body = ""; while(list($key, $val) = each($HTTP_POST_VARS)) { $body .= "$key: $val \n"; } mail("xx@xx.com", // to "Resume", $body, "From:".$Email); } // end form processing } ?> Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted October 9, 2011 Share Posted October 9, 2011 correction to my post.. $_FILE should be $_FILES Quote Link to comment Share on other sites More sharing options...
Scud Posted October 9, 2011 Author Share Posted October 9, 2011 It seems the code that Mancent has provided does not work properly, it results in a server error. I have added the if empty code AyKay47 provided however still results in the error 'there was an error uploading the file'. I have implemented it as follows; <?php if(!empty($_FILE)){ //proceed with code } else $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } /* this part can either be in the same file as the form or it can be in a different file. If you want this in a different file, make the "action" of the form go to that file */ if(sizeof($_POST)) { $body = ""; while(list($key, $val) = each($HTTP_POST_VARS)) { $body .= "$key: $val \n"; } mail("xx@xx.com", // to "Resume", $body, "From:".$Email); } // end form processing ?> Quote Link to comment Share on other sites More sharing options...
cloudll Posted October 9, 2011 Share Posted October 9, 2011 you first else is missing a { Quote Link to comment Share on other sites More sharing options...
Scud Posted October 9, 2011 Author Share Posted October 9, 2011 Sorry the code I'm using is; <?php if(!empty($_FILE)){ //proceed with code } else { $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } } /* this part can either be in the same file as the form or it can be in a different file. If you want this in a different file, make the "action" of the form go to that file */ if(sizeof($_POST)) { $body = ""; while(list($key, $val) = each($HTTP_POST_VARS)) { $body .= "$key: $val \n"; } mail("xx@xx.com", // to "Resume", $body, "From:".$Email); } // end form processing ?> Quote Link to comment Share on other sites More sharing options...
Scud Posted October 10, 2011 Author Share Posted October 10, 2011 ideas? Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted October 10, 2011 Share Posted October 10, 2011 what do you get with this? <?php if(!empty($_FILES)){ //proceed with code $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } } else { /* this part can either be in the same file as the form or it can be in a different file. If you want this in a different file, make the "action" of the form go to that file */ if(sizeof($_POST)) { $body = ""; while(list($key, $val) = each($HTTP_POST_VARS)) { $body .= "$key: $val \n"; } mail("xx@xx.com", // to "Resume", $body, "From:".$Email); } } // end form processing ?> Quote Link to comment Share on other sites More sharing options...
Scud Posted October 10, 2011 Author Share Posted October 10, 2011 That doesn't seem to work either, on my mac it just goes to a blank white page, where it continues trying to load the page however in IE i get the error 'the website cannot display the page' Quote Link to comment Share on other sites More sharing options...
Scud Posted October 11, 2011 Author Share Posted October 11, 2011 please help. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted October 12, 2011 Share Posted October 12, 2011 the blank screen means that something is happening.. more then likely you have a syntax error which is prohibiting the output to be sent.. check and make sure that you have these two settings at the top of your page.. error_reporting(E_ALL); ini_set("display_errors",1); this should output any present errors to your browser.. Quote Link to comment Share on other sites More sharing options...
Scud Posted October 12, 2011 Author Share Posted October 12, 2011 So i have finally managed how to find how to make it work after playing around with it for a while. The final script is as follows <?php $target = "upload/$firstname $lastname - "; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } elseif (!empty($_FILES)){ //proceed with code } else { echo "Sorry, there was a problem uploading your file."; } } /* this part can either be in the same file as the form or it can be in a different file. If you want this in a different file, make the "action" of the form go to that file */ if(sizeof($_POST)) { $body = ""; while(list($key, $val) = each($HTTP_POST_VARS)) { $body .= "$key: $val \n"; } mail("xx@xx.com", // to "Resume", $body, "From:".$Email); } // end form processing ?> Is it possible however to change the position of the echo. It simply displays at the top of the page to the left. I was hoping to fit it along nicer with my theme. How can i change this. Under my php script is a html file which displays a certain page, i was hoping i could incorporate the echo to become more a status on my page. Is there anyway to also send a direct link in the email to the uploaded file? Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted October 12, 2011 Share Posted October 12, 2011 1. you can use CSS to move the echo wherever you want.. 2. include the file path in your $body Quote Link to comment Share on other sites More sharing options...
Scud Posted October 12, 2011 Author Share Posted October 12, 2011 thanks for your help aykay. How can i do both of these things? I would like to place the echo function in a particular part of my page, what code do i insert where i would like it to be placed. Similarly what code do i insert into my php script to send the direct path. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted October 12, 2011 Share Posted October 12, 2011 1. wrap the code that you are outputting in an element tag like a <span>, then assign it a class and use CSS to move it wherever you like.. 2. if(sizeof($_POST)) { $body = ""; while(list($key, $val) = each($HTTP_POST_VARS)) { $body .= "$key: $val \n"; } $body .= "\n http://domain.com/path/to/file.jpg"; mail("xx@xx.com", // to "Resume", $body, "From:".$Email); } I have not used a mailer recently with PHP so I am not really sure if the image will show up as a link or not.. I'm sure someone else on here will know or your can look into online resources for that. Quote Link to comment Share on other sites More sharing options...
Scud Posted October 12, 2011 Author Share Posted October 12, 2011 AyKay was code to i insert on my page to change the location of the echo? Similarly what code do i insert in my php script to add a direct link into the body of my email? Thanks in advance Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted October 13, 2011 Share Posted October 13, 2011 well mail clients handle mail differently.. some you can get away with an anchor tag, some you can't.. perhaps you can inlude both an anchor tag linked to your picture, and a url to the image.. eg http://www.domain.com/path/to/image.jpg Quote Link to comment Share on other sites More sharing options...
Scud Posted October 13, 2011 Author Share Posted October 13, 2011 thanks for the above code. I have managed to insert a direct path into my email however it doesn't show up as a link just plain text. can you please give me an example of how i would move the echo function to a different part of the page? Quote Link to comment Share on other sites More sharing options...
Mancent Posted December 1, 2012 Share Posted December 1, 2012 echo it as a html page link? like any html link. just as php. 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.