PHP Upload Script

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 2119 Views - Last Post: 07 August 2009 - 12:22 PM Rate Topic: -----

#16 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: PHP Upload Script

Posted 06 August 2009 - 05:37 PM

That's a Ternary Operator, basically it's the same as

if(isset($GET['number_of_fields']))
{
		$number_of_fields = (int)$_GET['number_of_fields'];
}
else
{
	   $number_of_fields = 5;
}


Was This Post Helpful? 1
  • +
  • -

#17 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: PHP Upload Script

Posted 06 August 2009 - 05:41 PM

Ahh i see, i've only used that kind before:

if(isset($GET['number_of_fields']))
{
		$number_of_fields = (int)$_GET['number_of_fields'];
}
else
{
	   $number_of_fields = 5;
}



but i shall give that link a read cheers PsychoCoder :)
Was This Post Helpful? 0
  • +
  • -

#18 gregwhitworth  Icon User is offline

  • Tired.
  • member icon

Reputation: 219
  • View blog
  • Posts: 1,604
  • Joined: 20-January 09

Re: PHP Upload Script

Posted 06 August 2009 - 09:02 PM

Dude - I'll freakin give you one if you want it bad enough. You can hack through it and see what I've done that makes it work and expound upon it.

You can see it here (built from scratch so be nice, and IE users I know that the drop downs don't work right now):

http://www.artservic...com/gallery.php
Was This Post Helpful? 0
  • +
  • -

#19 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: PHP Upload Script

Posted 07 August 2009 - 07:28 AM

Hey guys i'm still following this tutorial and have come to another part i don't understand i have tried googling it but didn't really get anything

Here is the code

$photo_category_list .= <<<__HTML_END
<option value="$row[0]">$row[1]</option>\n
__HTML_END;



i understand the <option value="$row[0]">..... bit but dont understand why they are using .= rather than just = and also i dont know what <<<__HTML_END...__HTMLEND; is?

cheers

tommyflint

Oh and greg that would be pretty cool if you dont mind as i could use it as a resource :)

edit: Just so you know i do know what .= does just don't understand why they have used it as the variable $photo_category_list has only just been created and nothing is currently in it. :)

This post has been edited by tommyflint: 07 August 2009 - 07:30 AM

Was This Post Helpful? 0
  • +
  • -

#20 gregwhitworth  Icon User is offline

  • Tired.
  • member icon

Reputation: 219
  • View blog
  • Posts: 1,604
  • Joined: 20-January 09

Re: PHP Upload Script

Posted 07 August 2009 - 08:29 AM

http://www.php.net/m....syntax.heredoc

That explains the <<<, it's called the heredoc syntax, and basically it allows you to have multiple line strings.

Also I searched, just in case if __HTML_END is an actual function and it isn't, so they are probably just using it as a label or something.
Was This Post Helpful? 1
  • +
  • -

#21 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: PHP Upload Script

Posted 07 August 2009 - 08:32 AM

Ahh i understand now :) cheers greg
Was This Post Helpful? 0
  • +
  • -

#22 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: PHP Upload Script

Posted 07 August 2009 - 09:52 AM

okay i have now finished the the upload script but i get an error on this line of code:

$result = mysql_query('SELECT category_id,category_name FROM gallery_category');


the error is: Parse error: parse error in C:\Program Files\wamp\www\gallery\preupload.php on line 13

and zend gives the error: Syntax Error: unexpected '$result'

any ideas

cheers,

tommyflint
Was This Post Helpful? 0
  • +
  • -

#23 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: PHP Upload Script

Posted 07 August 2009 - 10:52 AM

check line 12 ... sounds like you forgot the trailing ; so the $result variable is "unexpected"
Was This Post Helpful? 1
  • +
  • -

#24 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: PHP Upload Script

Posted 07 August 2009 - 11:09 AM

Yep looks like i forgot the ; on the previous line... durr

cheers RPGonzo
Was This Post Helpful? 0
  • +
  • -

#25 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: PHP Upload Script

Posted 07 August 2009 - 11:38 AM

Here i go again lol

I have finished the script but i know get an error: Notice: Undefined variable: photo_category_list in C:\Program Files\wamp\www\gallery\preupload.php on line 32

I do also get the form but the html to the form doesn't look right either.

I have looked through it multiple times changing things to see if it makes a difference but i have had no luck.

Here is the PHP script:

<?php
include 'config.inc.php';

//initialization
$photo_upload_fields = '';
$counter = 1;

//if we want more fields, then use, preupload.php?number_of_fields=20
$number_of_fields = (isset($GET['number_of_fields'])) ?
(int)($_GET['number_of_fields']) : 5;

//Build Category List
$result = mysql_query('SELECT category_id,category_name FROM gallery_category');
while($row = mysql_fetch_array($result)) {
	$photo_category_list .= <<<_HTML
	<option value="$row[0]">$row[1]</option>\n
	_HTML;
}

mysql_free_result($result);

//Build Image uploading fields
while($counter <= $number_of_fields {
$photo_upload_fields .= <<<_HTML
<tr><td>
Photo {$counter}:
<input name="photo_file[]" type="file" />
</td></tr>
<tr><td>
Caption:
<textarea name="photo_caption[]" cols="30" rows="1"></textarea>
</td></tr>
_HTML;
$counter++;
}

//Final Output
echo <<<_HTML
<html>
<head>
<title>Upload Photos</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="post" name="upload form">
<table width="90%" border="0" align="center" style="width: 90%;">
<tr><td>
Select Category
<Select name="category">
$photo_category_list
</select>
</td></tr>
<!-Insert Image Fields Here -->
$photo_upload_fields
<tr><td>
<input type="submit" name="submit" value="Add Photos" />
</td</tr>
</table>
</form>
</body>
</html>
_HTML;
?>



and here is the outputted HTML:

<br />
<b>Notice</b>:  Undefined variable: photo_category_list in <b>C:\Program Files\wamp\www\gallery\preupload.php</b> on line <b>32</b><br />
<html>
<head>
<title>Upload Photos</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="post" name="upload form">
<table width="90%" border="0" align="center" style="width: 90%;">
<tr><td>
Select Category
<Select name="category">
	<option value="1">My First Gallery</option>

	__HTML_END;
}
mysql_free_result( Resource id #4 );

//Build Image uploading fields
while(1 <= 5 {
 = <<<__HTML_END
<tr><td>
Photo 1:
<input name="photo_file[]" type="file" />
</td></tr>
<tr><td>
Caption:
<textarea name="photo_caption[]" cols="30" rows="1"></textarea>
</td></tr>
</select>
</td></tr>
<!-Insert Image Fields Here -->

<tr><td>
<input type="submit" name="submit" value="Add Photos" />
</td</tr>
</table>
</form>
</body>
</html>



See someone wouldn't mind having a read through it that would be great :)

cheers,

tommyflint
Was This Post Helpful? 0
  • +
  • -

#26 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: PHP Upload Script

Posted 07 August 2009 - 11:43 AM

Well looking at this section of code you're trying to add to a variable that hasnt been declared yet. To the best of my knowledge you cannot do this

//Build Category List
$result = mysql_query('SELECT category_id,category_name FROM gallery_category');
while($row = mysql_fetch_array($result)) {
	$photo_category_list .= <<<_HTML
	<option value="$row[0]">$row[1]</option>\n
	_HTML;
}



Try this

//Build Category List
$photo_category_list = "";
$result = mysql_query('SELECT category_id,category_name FROM gallery_category');
while($row = mysql_fetch_array($result)) {
	$photo_category_list .= <<<_HTML
	<option value="$row[0]">$row[1]</option>\n
	_HTML;
}


Was This Post Helpful? 1
  • +
  • -

#27 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: PHP Upload Script

Posted 07 August 2009 - 11:57 AM

Cheers PsychoCoder that solved the problem of the error but the outputted HTML still seems to be wrong i think it has something to do with the heredoc syntax <<<_HTML .... _HTML; i just cant work out where exactly

This post has been edited by tommyflint: 07 August 2009 - 11:58 AM

Was This Post Helpful? 0
  • +
  • -

#28 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: PHP Upload Script

Posted 07 August 2009 - 12:22 PM

okay i have found the problem with the heredoc syntax, i had an indentation on this part
//Build Category List
$photo_category_list = "";
$result = mysql_query('SELECT category_id,category_name FROM gallery_category');
while($row = mysql_fetch_array($result)) {
	$photo_category_list .= <<<_HTML
	<option value="$row[0]">$row[1]</option>\n
	_HTML;
}



but now i have changed that i get this error: Parse error: parse error in C:\Program Files\wamp\www\gallery\preupload.php on line 34

grr its never ending

This post has been edited by tommyflint: 07 August 2009 - 12:22 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2