nospeq Posted February 26, 2010 Share Posted February 26, 2010 hi all, i am frustrated. can you tell me why this is not working? <?php include 'config.inc'; $id = $_GET['id']; $wynik = mysql_query($zapytanie); // Get all the data from the "example" table $result = mysql_query("SELECT * FROM pracownicy WHERE pracownik_id=$id") or die(mysql_error()); // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo $row['imie']; echo $row['drugie_imie']; echo $row['nazwisko']; $skan_orzeczenie = $row['orzeczenie_skan']; $dowod_osobisty = $row['dowod_osobisty']; $paszport_pl = $row['paszport_pl']; $paszport_inny = $row['paszport_inny']; echo '<br /><br /><br />'; } if (($skan_orzeczenie != NULL ) or ($dowod_osobisty != NULL ) or ($paszport_pl != NULL ) or ($paszport_inny != NULL )){ echo "sa skany<br />"; if ($paszport_pl != NULL ){echo 'paszport pl<br />'; }; } ?> <? if (!isset($_REQUEST["submit"])) { ?> <br /><br /><br /> Typ skanu ktory chcesz załadować: <br /> <form method="POST" action="scan_manager.php?id=<? echo $id ?>" enctype="multipart/form-data"> <select id="typ_skanu"> <? if ($dowod_osobisty == NULL ){echo '<option value="28">Dowód osobisty</option>'; }; ?> <? if ($paszport_pl == NULL ){echo '<option value="29">Paszport PL</option>';}; ?> <? if ($paszport_inny == NULL ){echo '<option value="30">Paszport inny</option>';}; ?> </select> <br /> Wybierz plik <input type="file" name="skan"> <input type="hidden" name="id" value="<? echo $id?>"> <input type="submit" name="submit" value="wgraj"> </form> <? //-- save image to db -- } else { $hndl=fopen($_REQUEST["skan"],"r"); $isize=sizeof($_REQUEST["skan"]); $imgdata=""; while(!feof($hndl)){ $imgdata.=fread($hndl,$isize); }; $imgdata=addslashes($imgdata); $dbconn = @mysql_connect($dbserver,$dbuser,$dbpass) or exit("SERVER Unavailable"); @mysql_select_db($dbname,$conn) or exit("DB Unavailable"); $sql = "INSERT INTO skany VALUES (NULL,'". $_REQUEST["typ_skanu"] ."','". $imgdata ."')"; //$sql_upd_pracownik = "INSERT INTO pracownicy" //$sql_upd_pracownik = "UPDATE" @mysql_query($sql,$conn) or exit("QUERY FAILED!"); //mysql_close($conn); fclose($hndl); echo $_REQUEST["typ_skanu"]; }; ?> Quote Link to comment https://forums.phpfreaks.com/topic/193436-whats-wrong-with-file-uploading/ Share on other sites More sharing options...
Adam Posted February 26, 2010 Share Posted February 26, 2010 Can you tell us what's not working with it? Quote Link to comment https://forums.phpfreaks.com/topic/193436-whats-wrong-with-file-uploading/#findComment-1018382 Share on other sites More sharing options...
nospeq Posted February 26, 2010 Author Share Posted February 26, 2010 sure, it doesnt upload file. i forgot to post my config.inc: <? $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'admin'; $dbname = 'inplus'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname,$conn) or die(mysql_error()); ?> to be honest to check if it send params i tried also to echo _FILES['typ_skanu'] or echo _FILES['typ_skanu'] but nothing. it seems that it doesnt send params.... can you help me? Quote Link to comment https://forums.phpfreaks.com/topic/193436-whats-wrong-with-file-uploading/#findComment-1018386 Share on other sites More sharing options...
Adam Posted February 26, 2010 Share Posted February 26, 2010 As of PHP4.3 $_FILES information was removed from $_REQUEST, so you need to use $_FILES['skan'] instead.. Though you shouldn't be trying to create a file handle on an array anyway, you should be using the 'tmp_name' key: $hndl=fopen($_FILES["skan"]["tmp_name"],"r"); An even better solution would be to just use file_get_contents to reutrn the file data, and then mysql_real_escape_string to escape it. Of course you should be checking the upload was successful too.. Quote Link to comment https://forums.phpfreaks.com/topic/193436-whats-wrong-with-file-uploading/#findComment-1018391 Share on other sites More sharing options...
nospeq Posted February 26, 2010 Author Share Posted February 26, 2010 ok. thanks. i'll give a try. so also if i echo $_FILES["skan"]["typ_skanu"] it will work.... and in $hndl=fopen($_FILES["skan"]["tmp_name"],"r"); 'tmp_name' is a standard php variable or i have to do something? or... can you explain me on my example how to use: (if i dont make you bored file_get_contents() and mysql_real_escape_string() ??? thanks ! Quote Link to comment https://forums.phpfreaks.com/topic/193436-whats-wrong-with-file-uploading/#findComment-1018400 Share on other sites More sharing options...
Adam Posted February 26, 2010 Share Posted February 26, 2010 For "typ_skanu" (assuming you mean the select value), you should be using $_POST["typ_skanu"]. Only type="file" inputs would be in the $_FILES array. And yes, "tmp_name" is a standard $_FILES key for file inputs. Take a look at the PHP manual (about a quarter down the page) for more info on $_FILES. To replace how you currently read the file: $hndl=fopen($_REQUEST["skan"],"r"); $isize=sizeof($_REQUEST["skan"]); $imgdata=""; while(!feof($hndl)){ $imgdata.=fread($hndl,$isize); }; $imgdata=addslashes($imgdata); You could just use: $imgdata = file_get_contents($_FILES["skan"]["tmp_name"]); $imgdata = mysql_real_escape_string($imgdata); Quote Link to comment https://forums.phpfreaks.com/topic/193436-whats-wrong-with-file-uploading/#findComment-1018403 Share on other sites More sharing options...
nospeq Posted February 27, 2010 Author Share Posted February 27, 2010 hi, i tried many times and nothing. here is my config.inc (again) <? $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'admin'; $dbname = 'inplus'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname,$conn) or die(mysql_error()); ?> and my scan_manager.php with your suggestion: <?php include 'config.inc'; $id = $_GET['id']; $result = mysql_query("SELECT * FROM pracownicy WHERE pracownik_id=$id") or die(mysql_error()); // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo $row['imie']; echo $row['drugie_imie']; echo $row['nazwisko']; $skan_orzeczenie = $row['orzeczenie_skan']; $dowod_osobisty = $row['dowod_osobisty']; $paszport_pl = $row['paszport_pl']; $paszport_inny = $row['paszport_inny']; echo '<br /><br /><br />'; }; if (($skan_orzeczenie != NULL ) or ($dowod_osobisty != NULL ) or ($paszport_pl != NULL ) or ($paszport_inny != NULL )){ echo "sa skany<br />"; if ($paszport_pl != NULL ){echo 'paszport pl<br />'; }; }; if (!isset($_REQUEST['submit'])) { ECHO 'LALALA'; echo $_POST["typ_skanu"]; ?> <br /> Typ skanu ktory chcesz załadować: <br /> <form method="POST" action="<?php echo $_SERVER['PHP_SELF'] . '?id=' . $id ;?>" enctype="multipart/form-data"> <select id="typ_skanu"> <? if ($dowod_osobisty == NULL ){echo '<option value="28">Dowód osobisty</option>'; }; ?> <? if ($paszport_pl == NULL ){echo '<option value="29">Paszport PL</option>';}; ?> <? if ($paszport_inny == NULL ){echo '<option value="30">Paszport inny</option>';}; ?> </select><br /> Wybierz plik <input type="file" name="skan" /> <input type="hidden" name="id" value="<? echo $id?>" /> <input type="submit" name="submit" value="wgraj" /> </form> <? }; //-- save image to db -- if (isset($_REQUEST['submit'])){ echo 'bobobo'; $imgdata = file_get_contents($_FILES["skan"]["tmp_name"]); $imgdata = mysql_real_escape_string($imgdata); $insert_sql = mysql_query("INSERT INTO skany VALUES (NULL,'". $_POST["typ_skanu"] ."','". $imgdata ."')") or die(mysql_error()); echo $_POST["typ_skanu"]; }; ?> What makes me wonder is that it never goes to second part and it never does insert part, i dont get echo $_POST["typ_skanu"]; result. i never get file in my mysql. any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/193436-whats-wrong-with-file-uploading/#findComment-1018941 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.