steviez Posted March 6, 2007 Share Posted March 6, 2007 Hi, I have just added a section to my users profile page where they can upload a profile picture, the problem is that when i use the html code: <form method="post" enctype="multipart/form-data"> it will only upload the file and not upload and post to the database, if i use: <FORM method="post"> it will post the file name to the database but not upload. Just incase it helps.. my site uses smarty (Of witch i know nothing about) Any help would be great! Thanks Link to comment https://forums.phpfreaks.com/topic/41507-solved-image-upload-help/ Share on other sites More sharing options...
steviez Posted March 7, 2007 Author Share Posted March 7, 2007 anyone? Link to comment https://forums.phpfreaks.com/topic/41507-solved-image-upload-help/#findComment-201353 Share on other sites More sharing options...
redarrow Posted March 7, 2007 Share Posted March 7, 2007 POST YOUR UPLOAD CODE AND FORM? Link to comment https://forums.phpfreaks.com/topic/41507-solved-image-upload-help/#findComment-201356 Share on other sites More sharing options...
steviez Posted March 7, 2007 Author Share Posted March 7, 2007 This is my upload code along with the other functions of my php page: <?php session_start(); include("include/config.php"); include("include/function.php"); chk_member_login(); if($_REQUEST[update_profile]!="") { $bdate=$_REQUEST[year]."-".$_REQUEST[month]."-".$_REQUEST[day]; if($_REQUEST[email]=="") $err="Signup: Email should not be null."; // elseif(!check_email($_REQUEST[email]) && $_REQUEST[prevemail]!="$_REQUEST[email]") $err="Signup: Invalid Email format!"; elseif(check_field_exists($_REQUEST[email],"email","signup")==1 && $_REQUEST[prevemail]!="$_REQUEST[email]")$err="Signup: This email already exist!"; elseif($_REQUEST[password1]=="") $err="Signup: Password should not be null."; elseif($_REQUEST[password1]!=$_REQUEST[password2]) $err="Signup: Retype does not match."; elseif($bdate!="yyyy-mm-dd"){if(!checkdate($_REQUEST[month],$_REQUEST[day],$_REQUEST[year])) $err="Invalid date format";} if($err=="") { $addition=""; $addition.="fname='$_REQUEST[fname]',"; $addition.="lname='$_REQUEST[lname]',"; if($bdate!="yyy-mm-dd")$addition.="bdate='$bdate',"; if($_REQUEST[gender]!="---")$addition.="gender='$_REQUEST[gender]',"; if($_REQUEST[relation]!="---")$addition.="relation='$_REQUEST[relation]',"; $addition.="aboutme='$_REQUEST[aboutme]',"; $addition.="website='$_REQUEST[url]',"; $addition.="town='$_REQUEST[hometown]',"; $addition.="city='$_REQUEST[city]',"; $addition.="zip='$_REQUEST[zip]',"; if($_REQUEST[country]!="Select Country")$addition.="country='$_REQUEST[country]',"; $addition.="occupation='$_REQUEST[occupation]',"; $addition.="company='$_REQUEST[companies]',"; $addition.="school='$_REQUEST[schools]',"; $addition.="interest_hobby='$_REQUEST[hobbies]',"; $addition.="fav_movie_show='$_REQUEST[movies]',"; $addition.="fav_music='$_REQUEST[music]',"; $addition.="fav_book='$_REQUEST[books]',"; $addition.="profilepic='$_REQUEST[profilepic]',"; $sql="update signup set email='$_REQUEST[email]', $addition pwd='$_REQUEST[password1]' WHERE UID=$_SESSION[uID]"; $conn->execute($sql); /* Begin Upload The Profile Pic */ $uploaddir = "/home/steviez/YC9R5F01/htdocs/music4play/test/user_images/"; if(is_uploaded_file($_FILES['profilepic']['tmp_name'])) { move_uploaded_file($_FILES['profilepic']['tmp_name'],$uploaddir.'/'.$_FILES['profilepic']['name']); } print "Your file has been uploaded successfully! Yay!"; /* End Upload The Profile Pic */ if(mysql_affected_rows()==1) { if($_REQUEST[prevemail]!="$_REQUEST[email]") { $ran=time().rand(1,99999999); $sql="update verify as v, signup as s set v.vcode='$ran', s.emailverified='no' WHERE v.UID=s.UID and v.UID=$_SESSION[uID]"; $conn->execute($sql); STemplate::assign('vcode',$ran); $to=$_REQUEST[email]; $_SESSION[email]=$_REQUEST[email]; $name=$config['site_name']; $from=$config['admin_email']; $rs = $conn->execute("select * from emailinfo where email_id='verify_email'"); $subj = $rs->fields['email_subject']; $email_path = $rs->fields['email_path']; $mailbody=STemplate::fetch($email_path); mailing($to,$name,$from,$subj,$mailbody,$bcc=""); session_to_db(); } } } } $sql="select * from signup WHERE UID=$_SESSION[uID]"; $rs=$conn->execute($sql); $date=explode("-",$rs->fields[bdate]); STemplate::assign('err',$err); STemplate::assign('msg',$msg); STemplate::assign('days',days($date[2])); STemplate::assign('months',months($date[1])); STemplate::assign('years',years($date[0])); STemplate::assign('country',country_box($_REQUEST[country])); STemplate::assign('answers',$rs->getarray()); STemplate::assign('head_bottom',"homelinks.tpl"); STemplate::display('head1.tpl'); STemplate::display('err_msg.tpl'); STemplate::display('my_profile.tpl'); STemplate::display('footer.tpl'); ?> An this is the code from my template file for the page: <tr> <td align="center" valign="top"> <table width="760" border="0" cellspacing="0" cellpadding="0" > <tr><td width=10 rowspan=2> </td></tr> <tr> <td> <TABLE cellSpacing=0 cellPadding=5 width="750" border=0> <FORM method="post" enctype="multipart/form-data"> <INPUT type=hidden value=profile_submit name=command> <input type="hidden" name=prevemail value={$answers[0].email}> <TBODY> <TR><TD colSpan=2><DIV class=tableSubTitle></DIV></TD></TR> <TR> <TD colSpan=2> <DIV class=tableSubTitle> <DIV style="FONT-WEIGHT: normal; FONT-SIZE: 11px; FLOAT: right"> <A href="{$baseurl}/uprofile.php?UID={$answers[0].UID}"> View Your Profile Page</A> </DIV>Account Information: </DIV>* Indicates required field.</TD> </TR> <TR> <TD align=right width=200><SPAN class=label>Email:</SPAN></TD> <TD><INPUT maxLength=60 size=30 value="{$answers[0].email}" name=email> *</TD> </TR> <TR> <TD align=right><SPAN class=label>User Name:</SPAN></TD> <TD>{$answers[0].username}</TD> </TR> <TR> <TD align=right><SPAN class=label>Password:</SPAN></TD> <TD><INPUT type=password maxLength=20 value="{$answers[0].pwd}" name=password1> *</TD> </TR> <TR> <TD align=right><SPAN class=label>Retype Password:</SPAN></TD> <TD><INPUT type=password maxLength=20 value={$answers[0].pwd} name=password2> *</TD> </TR> <TR> <TD class=small colSpan=2> </TD> </TR> <TR> <TD colSpan=2> <DIV class=tableSubTitle>Personal Information:</DIV></TD></TR> <TR> <TD align=right><SPAN class=label>First Name:</SPAN></TD> <TD><INPUT maxLength=30 size=30 name=fname value="{$answers[0].fname}"></TD></TR> <TR> <TD align=right><SPAN class=label>Last Name:</SPAN></TD> <TD><INPUT maxLength=30 size=30 name=lname value="{$answers[0].lname}"></TD></TR> <TR> <TD align=right><SPAN class=label>Birthday:</SPAN></TD> <TD> <SELECT name=month><OPTION>mm</OPTION>{$months}</SELECT> <SELECT name=day><OPTION>dd</OPTION>{$days}</SELECT> <SELECT name=year><OPTION>yyyy</OPTION>{$years}</SELECT> </TD> </TR> <TR> <TD align=right><SPAN class=label>Gender:</SPAN></TD> <TD> <SELECT name=gender> <OPTION value="">---</OPTION> <OPTION value=Female {if $answers[0].gender eq "Female"}selected{/if}>Female</OPTION> <OPTION value=Male {if $answers[0].gender eq "Male"}selected{/if}>Male</OPTION> </SELECT> </TD> </TR> <TR> <TD align=right><SPAN class=label>Relationship Status:</SPAN></TD> <TD> <SELECT name=relation> <OPTION value="">---</OPTION> <OPTION value=Single {if $answers[0].relation eq "Single"}selected{/if}>Single</OPTION> <OPTION value=Taken {if $answers[0].relation eq "Taken"}selected{/if}>Taken</OPTION> <OPTION value=Open {if $answers[0].relation eq "Open"}selected{/if}>Open</OPTION> </SELECT> </TD> </TR> <TR vAlign=top> <TD align=right> <SPAN class=label>About Me:</SPAN><BR> <SPAN class=small>(Describe Yourself) </SPAN> </TD> <TD><TEXTAREA name="aboutme" rows=5 cols=45>{$answers[0].aboutme}</TEXTAREA></TD> </TR> <TR> <TD align=right><SPAN class=label>Personal Website:</SPAN></TD> <TD><INPUT maxLength=255 size=40 name=url value="{$answers[0].website}"></TD> </TR> <TR> <TD align=right> </TD> <TD><img src="" alt="" /></TD> </TR> <TR> <TD align=right><SPAN class=label>Your Image :</SPAN></TD> <TD><input type="file" name="profilepic" class="button" /></TD> </TR> <TR> <TD class=small colSpan=2> </TD> </TR> <TR> <TD colSpan=2><DIV class=tableSubTitle>Location Information:</DIV></TD> </TR> <TR> <TD align=right><SPAN class=label>Hometown:</SPAN></TD> <TD><INPUT maxLength=120 size=30 name=hometown value="{$answers[0].town}"></TD></TR> <TR> <TD align=right><SPAN class=label>Current City:</SPAN></TD> <TD><INPUT maxLength=120 size=30 name=city value="{$answers[0].city}"></TD></TR> <TR> <TD align=right><SPAN class=label>Current Zip:</SPAN> <BR> <SPAN class=small>(US & Canada Only) </SPAN> </TD> <TD><INPUT maxLength=5 size=5 name=zip value="{$answers[0].zip}"></TD> </TR> <TR> <TD align=right><SPAN class=label>Current Country:</SPAN></TD> <TD> <SELECT name=country> <OPTION value="">Select Country</OPTION>{$country} </SELECT> </TD> </TR> <TR> <TD class=small colSpan=2> </TD></TR> <TR> <TD colSpan=2> <DIV class=tableSubTitle>Random Information:</DIV>Separate items with commas.</TD></TR> <TR> <TD align=right><SPAN class=label>Occupations:</SPAN></TD> <TD><INPUT maxLength=500 size=40 name=occupation value="{$answers[0].occupation}"></TD></TR> <TR> <TD align=right><SPAN class=label>Companies:</SPAN></TD> <TD><INPUT maxLength=500 size=40 name=companies value="{$answers[0].company}"></TD></TR> <TR> <TD align=right><SPAN class=label>Schools:</SPAN></TD> <TD><INPUT maxLength=500 size=40 name=schools value="{$answers[0].school}"></TD></TR> <TR vAlign=top> <TD align=right><SPAN class=label>Interests & Hobbies:</SPAN></TD> <TD><TEXTAREA name=hobbies rows=5 cols=45>{$answers[0].interest_hobby}</TEXTAREA></TD></TR> <TR vAlign=top> <TD align=right><SPAN class=label>Favorite Movies & Shows:</SPAN></TD> <TD><TEXTAREA name=movies rows=5 cols=45>{$answers[0].fav_movie_show}</TEXTAREA></TD></TR> <TR vAlign=top> <TD align=right><SPAN class=label>Favorite Music:</SPAN></TD> <TD><TEXTAREA name=music rows=5 cols=45>{$answers[0].fav_music}</TEXTAREA></TD></TR> <TR vAlign=top> <TD align=right><SPAN class=label>Favorite Books:</SPAN></TD> <TD><TEXTAREA name=books rows=5 cols=45>{$answers[0].fav_book}</TEXTAREA></TD></TR> <TR> <TD> </TD> <TD><INPUT type=submit value="Update Profile" name="update_profile"></TD> </TR> </FORM> </TBODY> </TABLE> </td> </tr> </table> </td></tr> The pages use smarty Link to comment https://forums.phpfreaks.com/topic/41507-solved-image-upload-help/#findComment-201379 Share on other sites More sharing options...
redarrow Posted March 7, 2007 Share Posted March 7, 2007 form needs this order. <!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" action="__URL__" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> example of code move_uploaded_file() for further information. The following example will process the file upload that came from a form. <?php // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead // of $_FILES. $uploaddir = '/var/www/uploads/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); echo '<pre>'; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; } echo 'Here is some more debugging info:'; print_r($_FILES); print "</pre>"; ?> link http://uk2.php.net/features.file-upload Link to comment https://forums.phpfreaks.com/topic/41507-solved-image-upload-help/#findComment-201382 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.