Page 1 of 1

what's wrong with file uploading

Posted: Fri Feb 26, 2010 1:54 am
by nospeq
hi all,

can you help me with this code? i dont know what is wrong....

Code: Select all

 
    <?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"];
};
?>
 

Re: what's wrong with file uploading

Posted: Fri Feb 26, 2010 4:06 am
by Darhazer
Why you think there is something wrong? Are you getting any error messages? Or something you think should work doesn't? Give us a starting point.

Re: what's wrong with file uploading

Posted: Fri Feb 26, 2010 4:35 am
by nospeq
sorry. you are right.
i have no error messages.
and i have no uploaded file in mysql

i got a point that instead of:

Code: Select all

$hndl=fopen($_REQUEST["skan"],"r");
  $isize=sizeof($_REQUEST["skan"]);
 
  $imgdata="";
  while(!feof($hndl)){
    $imgdata.=fread($hndl,$isize);
  };
 
  $imgdata=addslashes($imgdata);
i could just use:

Code: Select all

 
 
$imgdata = file_get_contents($_FILES["skan"]["tmp_name"]);
$imgdata = mysql_real_escape_string($imgdata);
any other ideas. sorry i am not at home so i cannot try...