Strlen() expects parameter 1 to be string

strlen() expects parameter 1 to be string line 4 apparently :slight_smile:

? who, what, what? any ideas peeps?:cool:

<?php

$errmsg = “help”;
if (! @mysql_connect(“localhost”,“root”,“nottelling”) {
$errmsg = “Cannot connect to database”;
print ($errmsg);
exit();
}
@mysql_select_db(“mydb”);

// get the .pdf

$gotten = @mysql_query(“select * from pdf order by pid desc limit 1”);
$row = @mysql_fetch_assoc($gotten);
$bytes = $row[imgdata];
header(“Content-type: application/pdf”);
header(‘Content-disposition: attachment; filename=“thefile.pdf”’);
print $bytes;
?>

not sure if this is your answer or not…

You’re missing )

if(! @mysql_connect(“localhost”,“root”,“nottelling”) {

should be

if(! @mysql_connect(“localhost”,“root”,“nottelling”)) {

Where is the use of strlen() function? I did not see that. The error pointed rustybuddy is different and it should report something differently ‘syntax error expected ‘}’’ or something.

Some suggestions:

  • Do not suppress errors with @ at least when you are in development phase.
  • Use some PHP IDEs which tell you error while typing/coding.

Yeah, I was wondering why he was suppressing errors as well. Obviously we’re in the dev phase here trying to debug and we’re hiding errors… kinda like trying to debug javascript with IE :smiley:

Hi all, cheers for help here, this is the file I have issue with? any ideas, the file seems to upload to db ok?

Notice: Use of undefined constant completed - assumed ‘completed’ in C:\wamp\www\pdf\pdfstore.php on line 10

Warning: strlen() expects parameter 1 to be string, resource given in C:\wamp\www\pdf\pdfstore.php on line 14

Notice: Use of undefined constant whatsit - assumed ‘whatsit’ in C:\wamp\www\pdf\pdfstore.php on line 16

<?php

$errmsg = “”;
if (! @mysql_connect(“localhost”,“root”,“not telling”)) {
$errmsg = “Cannot connect to database”;
}
@mysql_select_db(“mydatabase”);

if ($errmsg == “”) {
if ($_REQUEST[completed] == 1) {
move_uploaded_file($_FILES[‘imagefile’][‘tmp_name’],“latest.img”);
$instr = fopen(“latest.img”,“rb”);
$image = mysql_real_escape_string(fread($instr,filesize(“latest.img”)));
if (strlen($instr) < 1000000) {
mysql_query (“insert into pdf (title, imgdata) values (\”“.
$_REQUEST[whatsit].
“\”, \”“.
$image.
“\”)”);
$errmsg = “Done”;
} else {
$errmsg = “Too large!”;
}
} else {
$errmsg = “Form not completed”;
}}
?>
<html>
<head>
<title>.pdf uploaded</title>
<body>
Operation status: <?= $errmsg ?><br>
Click <a href=pdfget.php>here</a> to download latest .pdf<br>
Click <a href=pdfup.php>here</a> to get an upload form
</body>
</html>

could you also advise on the hiding errors issue? am I hiding errors?

>if ($_REQUEST[completed] == 1) {
Put texts (here: completed) in quotes, otherwise PHP treats them as constants which results in the given errors:
if ($_REQUEST[‘completed’] == 1) {

>$instr = fopen(“latest.img”,“rb”);
>…
>if (strlen($instr) < 1000000) {
$instr is a filehandle, not a string.
Use this:
$instr = file_get_contents(‘latest.img’);
if (strlen($instr) < 1000000) {

cool, thanks for that, sorted it, cheers massive help :cool::slight_smile:

Yes, the operator @ in front of any functions just suppresses the errors/warnings which tell you the problem. See more here:
http://php.net/manual/en/language.operators.errorcontrol.php

ah I see, thanks