Forum Moderators: coopster

Message Too Old, No Replies

Upload pictures code problem...

         

AlexLee

11:53 am on Jan 27, 2005 (gmt 0)

10+ Year Member



I am currently using the picture upload code with auto thumbnailing found here [webmasterworld.com] msg #29

I am currently getting this error.

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\Program Files\Apache Group\Apache2\htdocs\FYP\loademup.php on line 30

Line 30 happens to be: print "<strong>$_FILES['userfile']['name'][$q]</strong> did not upload!";

And when I removed it, this happens: Notice: Undefined variable: userfile in C:\Program Files\Apache Group\Apache2\htdocs\FYP\loademup.php on line 12

Robber

12:21 pm on Jan 27, 2005 (gmt 0)

10+ Year Member



Your quote problem can be solved by either:

1) print "<strong>".$_FILES['userfile']['name'][$q]."</strong> did not upload!";

or

2)
print "<strong>{$_FILES['userfile']['name'][$q]}</strong> did not upload!";

The notice you are getting means the vriable you use on line 12 called userfile has not yet been defined.

AlexLee

12:59 pm on Jan 27, 2005 (gmt 0)

10+ Year Member



Over at the submit form HTML, the userfile are coded like this. In arrays.

<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />

So how do I define them?

coopster

3:23 am on Jan 30, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What Robber is trying to explain is that you have your concatenation incorrect. Have a closer look at the message, comparing your line with the two alternatives offered by Robber. A quick review of Array do's and don'ts [php.net] might help clear things up.

AlexLee

3:53 pm on Jan 31, 2005 (gmt 0)

10+ Year Member



Notice: Undefined variable: userfile in C:\Program Files\Apache Group\Apache2\htdocs\FYP\loademup.php on line 12

This is line 12: $tot = count($userfile);
Yes, I've noticed that it is not defined yet.

I tried $userfile = $_POST["userfile"];
and $userfile = $_POST["userfile[]"];
But both don't work.

The form is as follows:


<form enctype="multipart/form-data" action="loademup.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="300000">
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input type="submit" />
</form>

Or can someone direct me to another similar script?
One that creates thumbprint, allows upload of all picture types, etc...

dreamcatcher

4:12 pm on Jan 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, I've noticed that it is not defined yet.

And thats why the error is occurring. Try using isset() before you use the userfile variable. Also, use $_FILES and not $_POST.

if (isset($_FILES['userfile']))
{
//execute the loop and do rest of code
}

also as its an array, try using empty to determine if the array contains data

if (isset($_FILES['userfile']) &&!empty($_FILES['userfile']))
{
//execute the loop and do rest of code
}

AlexLee

4:18 pm on Jan 31, 2005 (gmt 0)

10+ Year Member



Thanks to everyone for their help.

I was just browsing the forum and came across this code for image upload [webmasterworld.com]. The codes are short and simple. Just what I need. I had managed to make it upload pictures for me.

But is it possible to make it create a thumbnail for me too?