Jump to content

doforumda

Members
  • Posts

    300
  • Joined

  • Last visited

    Never

Everything posted by doforumda

  1. i want to upload file with php. my code is below. I describe my problem below the whole code upload.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="uploadProcess.php" method="post" enctype="multipart/form-data"> <input type="file" name="myfile" /><p> <input type="submit" name="submit" value="Upload" /> </form> </body> </html> uploadProcess.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php include("getExtension.php"); include("imageResizer.php"); $name = $_FILES['myfile']['name']; $type = $_FILES['myfile']['type']; $size = $_FILES['myfile']['size']; $temp_name = $_FILES['myfile']['tmp_name']; $error = $_FILES['myfile']['error']; echo $temp_name."<br>"; echo $name."<br>"; $ext = getExtension($name); $ext = strtolower($ext); echo $ext."<br>"; //die(); if($error == 0) { $location = "photos/".$name; if($size <= 1000000) { if($ext == "png" || $ext == "jpeg" || $ext == "jpg" || $ext == "gif") { if(!file_exists($location)) { //move_uploaded_file($temp_name, $location); image($name,$ext); echo "File uploaded successfully."; } else die("This file is already exists."); } else die("This format is not supported. Only png, jpeg, jpg and gif images are supported."); } else die("File size is too big."); } else die("There is an error uploading code: $error"); ?> </body> </html> imageResizer.php <?php function image($name, $ext) { // The file $filename = $name; $percent = 0.05; $save = "photos/".$name; // Content type header('Content-type: image/'.$ext); // Get new dimensions list($width, $height) = getimagesize($filename); $new_width = $width * $percent; $new_height = $height * $percent; if($width > 60 && $height > 60) { // Resample $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); } else { $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height); } // Output imagejpeg($image_p, $save, 100); } //image('test.jpg','jpg'); ?> here the problem is in upload Process.php when i call function image($name,$ext); the it does not save my file on the server but when i call this function like this image('image.jpg','jpg'); then it saves this file on the server. how can i fix this so it saves file when i pass variables as parameters?
  2. hi i am not sure what the problem is with the code below. Everytime i run this code it displays this http://localhost/fileupload/imageResizer.php and i want to display the image. what is the problem please reply <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $filename = 'test.jpg'; $percent = 0.5; header('Content-type: image/jpeg'); list($width, $height) = getimagesize($filename); $new_width = $width * $percent; $new_height = $height * $percent; $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($image_p, null, 100); ?> </body> </html>
  3. ok let me ask about image magick i also learn abit about that. What will i do if i use image magick and then upload that to webserver so what will i do i mean will to enable image magick on the webserver as it is out of my reach so what step should i take?
  4. ok it is fine now its working but still same bad quality of the image
  5. now it is displaying this output "http://localhost/uploadfile/resizeimage.php"
  6. ok. so i dont know whether my webserver supports imagick. thorpe can please solve this problem on following link http://www.phpfreaks.com/forums/index.php/topic,288921.0.html
  7. thanks thorpe. i have another question. what will i do when i upload my website to the server? I mean to ask will i install imagick on the server as well? i will do something else?
  8. hi i need some help using imagick. i just download imagick from url below http://www.imagemagick.org/script/binary-releases.php#windows i download this version ImageMagick-6.5.9-10-Q16-windows-dll.exe now i am trying to use the code which is in php.net website but it is not working. i think i did not install it correctly. i just run .exe file. is that enough to use i magick?? this is the php.net code <?php header('Content-type: image/jpeg'); $image = new Imagick('image.jpg'); // If 0 is provided as a width or height parameter, // aspect ratio is maintained $image->thumbnailImage(100, 0); echo $image; ?> above code displays this http://localhost/uploadfile/imagicexample.php
  9. now i am using imagecopyresized and my code is working fine. the problem only is when my image is resizes to thumbnail then its quality gets bad. Why is that and how can i maintain the quality of my image? <?php function imagetothumb($imagename, $extension) { $save = "thumb/".$imagename; $filename = $imagename;//'image.jpg'; $percent = 0.05; //$width = 50; //$height = 50; header('Content-type: image/'.$extension); list($width, $height) = getimagesize($filename); $newwidth = $width * $percent; $newheight = $height * $percent; $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefromjpeg($filename); imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagejpeg($thumb,$save,100); } function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $imagename = "image3.jpg"; $ext = getExtension($imagename); $ext = strtolower($ext); //imageresizer($imagename,$ext); imagetothumb($imagename,$ext); ?>
  10. hi i am trying to upload an image and resize it to thumbnail size. how can i resize that image which is being uploaded? i want to resize my image to width=50 and height=50 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="fileupload.php" method="post" enctype="multipart/form-data"> <input type="file" name="myfile" /><p> <input type="submit" name="submit" value="Upload" /> </form> </body> </html> fileupload.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $name = $_FILES["myfile"]["name"]; $type = $_FILES["myfile"]["type"]; $size = $_FILES["myfile"]["size"]; $temp_name = $_FILES["myfile"]["tmp_name"]; $error = $_FILES["myfile"]["error"]; function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $ext = getExtension($name); $ext = strtolower($ext); if($error == 0) { $location = "upload/".$name; if($ext == "png" && $ext == "jpg" && $ext == "jpeg" && $ext == "gif") { if($size > 2000000) { if(!file_exists($location)) { move_uploaded_file($temp_name,$location); //query database to add location and image name. echo "Upload Complete."; } else die("File already exist."); } else die("format is not allowed or file size is too big"); } else die("it is too big size."); } else die("Error uploading file! code $error."); ?> </body> </html>
  11. quite complex i am not sure how this can be done.
  12. you mean like this table name= universities uniid userid uniName table name=degrees degreeid userid degree
  13. currently my table has following data. It means that currently logged in user with userid 1 has three degrees from three universities. Now let suppose if he wants to edit first one so i need an update query and i explained above what happens when i try update. and other thing is what if he wants to edit 1st entry and add an extra degree with another university. in this case i ll need one insert and one update query. how can this be done. [attachment deleted by admin]
  14. here is the same form as above in my post i changed variable names and db and table. here what my form is doing. when user logs in and wants to edit his education information he clicks on Edit. then below form appears. he then selects different universities and degrees from the list by clicking the link "Add" to add more fields in the form. my form code is below <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" src="lib/jquery-1.4.min(Production).js"></script> <script> var id = 0; function addFormField() { //document.getElementById("id").value; id++; $("#divTxt").append( "<p>" + "<label>University </label>" + "<select name='university[]' id='relation" + id + "'>" + "<option value='uit'>UIT</option>" + "<option value='nun'>NUN</option>" + "<option value='fast'>FAST</option>" + "<option value='au'>AU</option>" + "<option value='vu'>VU</option>" + "</select>" + "<input type='text' name='degree[]' />" + "<a href='#' onClick='removeFormField(\"#row" + id + "\"); return false;'>Remove</a>" + "</p>" ); } function removeFormField(id) { $(id).remove(); } </script> </head> <body> <form action="dynamicfieldsProcess.php" method="post" id="form1"> <label>University</label> <select name="university[]" id="relation0"> <option value="uit">UIT</option> <option value="nun">NUN</option> <option value="fast">FAST</option> <option value="uop">UOP</option> <option value="au">AU</option> <option value="vu">VU</option> </select> <input type="text" name="degree[]" /> <div id="divTxt"></div> <p><input type="submit" value="Submit" name="submit"> <!-- <input type="reset" value="Reset" name="reset"> --></p> </form> <p><a href="#" onClick="addFormField(); return false;">Add</a></p> </body> </html> then when all the values are submitted. what i want to do with them is 1st. check whether this user already has data in the table. if user has data lets say 3 universities and 3 degrees with his userid. then update all these values and if user wants to add 4th one then update the previous 3 and add the extra 4th university and degree in the table. here is the code of all this <?php $_SESSION['userid'] = 1; $university = $_POST['university']; $degree = $_POST['degree']; $connect = mysql_connect("localhost","user","pass"); mysql_select_db("test"); //print_r($_POST); $get = "SELECT * FROM university WHERE userid='$_SESSION[userid]'"; $get_result = mysql_query($get); $count = mysql_num_rows($get_result); $uni = $count['university']; echo $uni; if($count > 0) { while($row = mysql_fetch_assoc($get_result)) { $uni = $row['university']; $deg = $row['degree']; //echo $univers."<br>"; } for($i = 0; $i < count($_POST['university']); $i++) { $uni = $university[$i]; $deg = $degree[$i]; $update = "UPDATE university SET university='$uni', degree='$deg' WHERE userid='$_SESSION[userid]'"; //$result_update = mysql_query($update); } } if user doesnt have any data in the table then simply insert the data in the table. code for this is here else { for($i = 0; $i < count($_POST['university']); $i++) { $uni = $university[$i]; $deg = $degree[$i]; //echo $uni.": ".$deg."<br>"; $add = "INSERT INTO university VALUES ('','$_SESSION[userid]','$uni','$deg')"; //echo $add."<br>"; //$result = mysql_query($add); } } ?> above code works perfectly but the problem is with update. when i try to update it updates all the fields with userid currently logged in with only one value from the table whereas my php script gets all the values from html form. so how can i update this dynamic form? my complete code is here <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $_SESSION['userid'] = 1; $university = $_POST['university']; $degree = $_POST['degree']; $connect = mysql_connect("localhost","user","pass"); mysql_select_db("test"); //print_r($_POST); $get = "SELECT * FROM university WHERE userid='$_SESSION[userid]'"; $get_result = mysql_query($get); $count = mysql_num_rows($get_result); $uni = $count['university']; echo $uni; if($count > 0) { while($row = mysql_fetch_assoc($get_result)) { $uni = $row['university']; $deg = $row['degree']; //echo $univers."<br>"; } for($i = 0; $i < count($_POST['university']); $i++) { $uni = $university[$i]; $deg = $degree[$i]; $update = "UPDATE university SET university='$uni', degree='$deg' WHERE userid='$_SESSION[userid]'"; //$result_update = mysql_query($update); } } else { for($i = 0; $i < count($_POST['university']); $i++) { $uni = $university[$i]; $deg = $degree[$i]; //echo $uni.": ".$deg."<br>"; $add = "INSERT INTO university VALUES ('','$_SESSION[userid]','$uni','$deg')"; //echo $add."<br>"; //$result = mysql_query($add); } } ?> </body> </html>
  15. now i modify my code to this print_r($_POST); for($i=0; $i<count($_POST['relation']); $i++) { //$imscreenname = $_POST['relation'][$i]; //$imname = $_POST['name'][$i]; //echo $screename."<br>"; //echo $name."<br>"; $imscreenname = $screenname[$i]; $imname = $name[$i]; $screennamesave = "INSERT INTO contacts VALUES ('1','$screenname','$name')" or die(mysql_error()); //$screennamesave = "UPDATE contacts SET name='$screenname', im='$name' WHERE userid='1'" or die(mysql_error()); $result = mysql_query($screennamesave); echo $screennamesave; } this is the display. this time i chose all the options from my select menu by adding more dynamic fields Array ( [relation] => Array ( [0] => brother [1] => sister [2] => father ) [name] => Array ( [0] => bro [1] => sis [2] => father ) [submit] => Submit ) INSERT INTO contacts VALUES ('1','Array','Array')INSERT INTO contacts VALUES ('1','Array','Array')INSERT INTO contacts VALUES ('1','Array','Array')
  16. i changed it and i get this thing Array ( [relation] => Array ( [0] => brother ) [name] => Array ( [0] => bro ) [submit] => Submit ) Notice: Undefined variable: imscreename in C:\wamp\www\examples\addDynamicFields.php on line 20 bro INSERT INTO contacts VALUES ('1','Array','Array')
  17. i get this now Array ( [relation] => Array ( [0] => brother ) [name] => Array ( [0] => bro ) [submit] => Submit ) Notice: Undefined variable: imscreename in C:\wamp\www\examples\addDynamicFields.php on line 20 bro INSERT INTO contacts VALUES ('1','Array','Array')
  18. this is what it says Array ( [relation] => Array ( [0] => brother ) [name] => Array ( [0] => bri ) [submit] => Submit )
  19. not even insert is working $screennamesave = "INSERT INTO contacts VALUES ('1','$screenname','$name')" or die(mysql_error());
  20. now i tried this but this still doesnt work. it neither update my db nor display anything means no errors no echo statments. for($i=1; $i<count($_POST['relation']); $i++) { $imscreenname = $_POST['relation'][$i]; $imname = $_POST['name'][$i]; echo $imscreename."<br>"; echo $imname."<br>"; $imscreenname = $screenname[$i]; $screennamesave = "UPDATE contacts SET name='$screenname', im='$name' WHERE userid='1'" or die(mysql_error()) or die(mysql_error()); $result = mysql_query($screennamesave); echo $screennamesave; }
  21. let me explain this. my form is dynamic. when my form first loads there is a label "Relation" in front of it there is select menu in front of select menu there is input text field. below this there is a submit button and below submit button there is "add" link. so when user clicks on add link then one more set of field like above it appeared. and there is a no limit how many a user can add form fields this is way they are allowed. so when user input lets suppose 6 fields then i want all of the data goes to php file and update that data for current logged in user. so how can this be done to get all the data and update all the data in my db table? my table is something like this. [attachment deleted by admin]
  22. hi i have a dynamic form. i need help in how can i use update query when values from dynamic form get pass to php file. currently when i press submit it displays this and does not update fields UPDATE contacts SET name='Array', im='Array' WHERE userid='1' this my code for dynamic form <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" src="lib/jquery-1.4.min(Production).js"></script> <script> var id = 0; function addFormField() { //document.getElementById("id").value; id++; $("#divTxt").append( "<p id='row" + id + "'><label>Relation <select name='relation[]' id='relation" + id + "'><option value='brother'>Brother</option><option value='sister'>Sister</option><option value='father'>Father</option><option value='mother'>Mother</option></select> <input type='text' name='name[]' /> <a href='#' onClick='removeFormField(\"#row" + id + "\"); return false;'>Remove</a></p>" ); } function removeFormField(id) { $(id).remove(); } </script> </head> <body> <form action="addDynamicFields.php" method="post" id="form1"> <label>Relation</label> <select name="relation[]" id="relation0"> <option value="brother">Brother</option> <option value="sister">Sister</option> <option value="mother">Mother</option> <option value="father">Father</option> <option value="daughter">Daughter</option> <option value="son">Son</option> </select> <input type="text" name="name[]" /> <div id="divTxt"></div> <p><input type="submit" value="Submit" name="submit"> <!-- <input type="reset" value="Reset" name="reset"> --></p> </form> <p><a href="#" onClick="addFormField(); return false;">Add</a></p> </body> </html> this is my php file <?php $screenname = $_POST['relation']; $name = $_POST['name']; $connect = mysql_connect("localhost","user","pass"); mysql_select_db("test"); for($i=1; $i<count($screenname); $i++) { //$imscreenname = $_POST['screenname'][$i]; //$imname = $_POST['name'][$i]; //echo $imscreename; //$imscreenname = $screenname[$i]; $screennamesave = "UPDATE contacts SET name='$screenname', im='$name' WHERE userid='1'" or die(mysql_error()); $result = mysql_query($screennamesave); echo $screennamesave; } ?>
  23. hi i got some code from another site. i modified it according to my needs. what is it doing it adds dynamic form fields by clicking "add another" link. the problem is when logged in user wants to modify his contact details he clicks on edit then gets to this modification form where all the data in his db is selected and displayed in that form fields. so the problem here is when he clicks on add another link it adds up that many fields sets that appeared currently. means if there appeared four sets of fields then clicking on add another link will add four more fields. what i want is to add only one set of fields which contains of text field and select menu. my code is here <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#btnAdd').click(function() { var num = $('.clonedInput').length; var newNum = new Number(num + 1); var newElem = $('#input' + num).clone().attr('id', 'input' + newNum); newElem.children(':first').attr('id', 'name' + newNum).attr('name', 'name' + newNum); $('#input' + num).after(newElem); }); }); </script> <style> #myForm div { font-size:14px; margin-bottom: 10px; clear: left; } #myForm label { width: 125px; display: block; font-size:14px; font-weight: bold; color: #999; float: left; } #btnAdd { margin-left:130px; } </style> </head> <body> <form id="myForm" method="post" action="process.php"> <div> <label>First Name: </label><input type="text" name="fname" id="fname"><br> </div> <div> <label>Last Name: </label><input type="text" name="lname" id="lname"><br> </div> <?php $connect = mysql_connect("localhost","user","pass"); mysql_select_db("db"); $get_im = mysql_query("SELECT * FROM contactim WHERE userid='$_SESSION[userid]'"); $count = mysql_num_rows($get_im); while($get_contactim = mysql_fetch_assoc($get_im)) { $userim_db = $get_contactim['username']; $im_db = $get_contactim['im']; //echo $userim_db."<br>"; for($i = 1; $i <= $count; $i++) { ?> <div id="input1" class="clonedInput"> <label>IM Screen Names:</label> <input type="text" name="name[]" id="name1" value="<?php if($userim_db == "") { echo ""; } else { echo $userim_db; } ?>" /> <select name="screenname[]" id="screenname1"> <option value="AIM" <?php if($im_db == "AIM") { echo "SELECTED"; } ?>>AIM</option> <option value="gtalk" <?php if($im_db == "gtalk") { echo "SELECTED"; } ?>>Google Talk</option> <option value="skype" <?php if($im_db == "skype") { echo "SELECTED"; } ?>>Skype</option> <option value="windows" <?php if($im_db == "windows") { echo "SELECTED"; } ?>>Windows Live</option> <option value="yahoo" <?php if($im_db == "yahoo") { echo "SELECTED"; } ?>>Yahoo</option> </select><br /> <?php } } ?> </div> <div> <a href="#" id="btnAdd">Add another</a> </div> <input type="submit" name="submit" value="Submit"> </form> </body> </html>
  24. it is not creating any problem db design is fine these usernames are from gtalk and skype not from my own users table. this user id has only one username which is stored in users table. this one here is only for his contact details he might have different usernames in different messangers so he can give all of them here.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.