Forum Moderators: coopster

Message Too Old, No Replies

First PHP-based website.

         

ShoT

3:13 am on Mar 12, 2006 (gmt 0)

10+ Year Member



Hello,
This is my first serious PHP based project and Im having some difficulties. A friend of mine wrote a script for me a sort of gallery script, except theres no database. We were going for simplicity, so that all the owner has to do is drag and drop the pictures into the FTP and they would show in the gallery after a refresh. Now, this script pulls out the images from a directory, and gets the labels from the file name, for example, each jpg is labeled 17_BLUE_SUNSET_5, and so in the gallery it displays a thumbnail of the picture and "BLUE SUNSET". That's all fine.

Now, what I want to achieve is to display the 6 last pictures added on the main page, however, I talked to the owner and he said he wouldn't mind actually uploading the pictures through the website. Which is cool, because now I can achieve it through a database, so I wrote a script, and am getting the weirdest error of errors (atleast thats how I see it).

Here's the code for the script that's supposed to "upload the image and save path in the DB":

<?
include("config.php");
?>

<FORM ENCTYPE="multipart/form-data" ACTION="imageupload.php" METHOD="POST">
Choose the image: <INPUT TYPE="file" NAME="userfile"><br>
<INPUT TYPE="submit" VALUE="Upload">
</FORM>

<?php

$path = "../players/";
$max_size = 2000000;
//2 Mb, any bigger than that is overkill.

if (!isset($HTTP_POST_FILES['userfile'])) exit;

if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {

if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "Rozmiar pliku jest ponad 2 Mb.<br>\n"; exit; }
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") ¦¦ ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") ¦¦ ($HTTP_POST_FILES['userfile']['type']=="image/jpeg")) {

if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "Plik juz istnieje<br>\n"; exit; }

$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "Ladowanie Nie Pomyslne<br>\n"; exit; } else { echo "Ladowanie Pomyslne<br>\n"; }

// following line is for testing purposes only
echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n";

} else { echo "Wrong file type<br>\n"; exit; }

}

if($Upload)
{//begin of if($Upload).
// Set global variables to easier names
$imgpath = $HTTP_POST_FILES['userfile']['name']

//run the query which adds the data gathered from the form into the database

$result = mysql_query("INSERT INTO recentimages (imgpath)
VALUES ('$imgpath')",$connect);

echo "<center><h2>Path added successfully into database.</h2></center>"

}//end of else

?>

However, Im getting
an unexpected T_STRING on line 21, and unexpected T_VARIABLE on line 48, can anyone please help?

21: if (($HTTP_POST_FILES['userfile']['type']=="image/gif") ¦¦ ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") ¦¦ ($HTTP_POST_FILES['userfile']
48: $result = mysql_query("INSERT INTO recentimages (imgpath)

appi2

3:43 am on Mar 12, 2006 (gmt 0)

10+ Year Member



[quote]echo "<center><h2>Path added successfully into database.</h2></center>"[\quote]

missing ;

echo "<center><h2>Path added successfully into database.</h2></center>";

¦¦

ShoT

4:12 am on Mar 12, 2006 (gmt 0)

10+ Year Member



I have fixed all errors except:

Unexpected T_VARIABLE on line 42:

42: $result = mysql_query("INSERT INTO recentimages (imgpath)

dreamcatcher

12:41 pm on Mar 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is this line:

$imgpath = $HTTP_POST_FILES['userfile']['name']

You need a semi colon after it:

$imgpath = $HTTP_POST_FILES['userfile']['name'];

dc

ShoT

12:28 am on Mar 13, 2006 (gmt 0)

10+ Year Member



Yes, thank you very much, that did it, however, the script wasn't working so I had to modify a bit and its good now, thanks yet again.