porko2004 Posted February 23, 2010 Share Posted February 23, 2010 hi i am creating an upload page and i cant get it to connect to my web-servers database for text and doesn't upload the image can anyone help me this is the code. Upload.htm <body oncontextmenu="return false;"> <center> <form enctype="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="500000" /> <table border="0"> <tr><td>Character Name:</td><td> <input type="text" name="charname" maxlength="20"><font color=#ff0000 size=1> * required</font> </td></tr> <br><br> <tr><td>Choose an Image:</td><td> <input name="userfile" type="file" id="userfile" /><br /> <input type="submit" value="Upload Photo" name="upload2" id="upload2" /> </td></tr></table></form> </center> </body> Upload.php <?php ob_start(); $db=mysql_connect(127.0.0.1,honormeg_forum,7june1990) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db(honormeg_upload,$db); $uploadDir = 'uploads/'; $charname = $_POST['charname']; if(empty($charname)) { echo "<center>Input Character Name</center>"; echo "<center><br><a href=playerupload.htm>..:Back:..</a></center>"; } else if(isset($_POST['upload2'])) { $charname = $_POST['charname']; $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $filePath = $uploadDir . $fileName; $sql = move_uploaded_file($tmpName, $filePath); if (!$sql) { echo "<center>Error uploading file</center>"; echo "<center><br><a href=playerupload.htm>..:Back:..</a></center>"; exit; } else { $filePath = addslashes($filePath); $sql= 'INSERT INTO player (path, charname) VALUES ("'.$fileName.'", "'.$charname.'")'; mysql_query($sql) OR die (mysql_error()); if(!get_magic_quotes_gpc()) { $filePath = addslashes($filePath); } $sql= 'INSERT INTO player (path, charname) VALUES ("'.$fileName.'", "'.$charname.'")'; mysql_query($sql) OR die (mysql_error()); echo ' <div id="page"> <div id="content"> <div class="post"> <p class="meta"><center>Your image has been successfully uploaded</center></p> <div class="entry">';echo '<center><a href=playerupload.htm>..:Back:..</a></center> </div></div></div>'; } ob_flush(); ?> Link to comment https://forums.phpfreaks.com/topic/193056-little-problem-with-upload-page/ Share on other sites More sharing options...
bernardmoes Posted February 23, 2010 Share Posted February 23, 2010 i've got an upload page also, and i did it this way: <?php session_start(); include('SimpleImage.php'); function file_extension($filename) { $path_info = pathinfo($filename); return $path_info['extension']; } $upfile = $_FILES['uploadedfile']['name']; $fille = file_extension($upfile); $gebruikers = $_SESSION['inloggen']; if($fille == "jpg") { $target_path = "uploads/" . $gebruikers . ".jpg"; } elseif($fille == "png") { $target_path = "uploads/" . $gebruikers . ".png"; } elseif($fille == "gif") { $target_path = "uploads/" . $gebruikers . ".gif"; } if(file_exists($target_path)) { unlink($target_path); } if ($fille == "jpg" || $fille == "png" || $fille == "gif") { if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "Het plaatje ". basename( $_FILES['uploadedfile']['name']). " is succesvol geupload!"; $image = new SimpleImage(); $image->load($target_path); $image->resize(100,100); $image->save($target_path); } else { echo "Don't make the image too large to upload!"; } } else { echo "Wrong file! upload a picture, jpg, png or gif!"; } ?> This was for uploading images too, i've uncluded a class here too. i used simpleimage.php to resize and save the image. I hope you can use this. just grab the shit you need out of this code Link to comment https://forums.phpfreaks.com/topic/193056-little-problem-with-upload-page/#findComment-1016720 Share on other sites More sharing options...
sader Posted February 23, 2010 Share Posted February 23, 2010 change this $filePath = addslashes($filePath);$sql= 'INSERT INTO player (path, charname) VALUES ("'.$fileName.'", "'.$charname.'")'; into this $filePath = addslashes($filePath); echo $filePath; $sql= 'INSERT INTO player (path, charname) VALUES ("'.$fileName.'", "'.$charname.'")'; what u get? Link to comment https://forums.phpfreaks.com/topic/193056-little-problem-with-upload-page/#findComment-1016721 Share on other sites More sharing options...
bernardmoes Posted February 23, 2010 Share Posted February 23, 2010 oww sorry i will translate the text from dutch to english in the code <?php session_start(); include('SimpleImage.php'); function file_extension($filename) { $path_info = pathinfo($filename); return $path_info['extension']; } $upfile = $_FILES['uploadedfile']['name']; $fille = file_extension($upfile); $user = $_SESSION['inloggen']; if($fille == "jpg") { $target_path = "uploads/" . $user . ".jpg"; } elseif($fille == "png") { $target_path = "uploads/" . $user . ".png"; } elseif($fille == "gif") { $target_path = "uploads/" . $user . ".gif"; } if(file_exists($target_path)) { unlink($target_path); } if ($fille == "jpg" || $fille == "png" || $fille == "gif") { if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "the image ". basename( $_FILES['uploadedfile']['name']). " has been uploaded successfully!"; $image = new SimpleImage(); $image->load($target_path); $image->resize(100,100); $image->save($target_path); } else { echo "don't make the image too large to upload!!"; } } else { echo "Wrong file! upload an image of jpg, png or gif!"; } ?> here you are maybe it helps Link to comment https://forums.phpfreaks.com/topic/193056-little-problem-with-upload-page/#findComment-1016725 Share on other sites More sharing options...
porko2004 Posted February 23, 2010 Author Share Posted February 23, 2010 no that didn't work and bernardmoes your upload worked but the problem is im trying also to add text input so people can input there name and it appears in a database Link to comment https://forums.phpfreaks.com/topic/193056-little-problem-with-upload-page/#findComment-1017058 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.