Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/193436-whats-wrong-with-file-uploading/
Share on other sites

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?

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..

 

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 !

 

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);

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?

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.