Newb advice

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Newb advice

Post by jackpf »

You appear to be double escaping your profile data.

In my profile, something with slashes comes back as
<script>alert(\'hello\');</script>
I'll have a proper go at some h4x tonight with my tools (I'm at college atm) :twisted:
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Re: Newb advice

Post by MiniMonty »

What are you studying ?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Newb advice

Post by jackpf »

Maths, computing, physics and chemistry :)

Also, just noticed on http://www.shutterbugclub.com/edit_settings_parse.php you have a parse error. Not sure if you're editing it at this exact moment in time or something...but I just thought I'd warn you in case you hadn't yet realised.

I also can't seem to upload images :/

Haven't been able to hack you though, which is a bonus.
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Re: Newb advice

Post by MiniMonty »

Oh mate - physics ! Yeeeeah !
It's the entire truth of everything !

As for uploading that's the next big thing...

One big old form for logged in users to upload images to their own gallery, a general gallery,
specific galleries.... I've got to get my head around how it will best display for members and
joe public before I even design my wish list for that functionality.

I've been testing (and failing) but I'll soldier on for a bit because I want to learn this.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Newb advice

Post by jackpf »

Yeah, it's pretty cool. :)

Oh right. I was just thinking, why not have a select box to allow the user to select the gallery they want to upload to rather than seperate forms?

I think you should do the same for profile editing as well...rather than having a seperate submit button for each field, just have one.

Anyway, cool. Good luck. I'll have a go at hacking your uploads as well if you want (when you're done) ;)
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Re: Newb advice

Post by MiniMonty »

jackpf wrote:Yeah, it's pretty cool. :)

Oh right. I was just thinking, why not have a select box to allow the user to select the gallery they want to upload to rather than seperate forms?

I think you should do the same for profile editing as well...rather than having a seperate submit button for each field, just have one.

Anyway, cool. Good luck. I'll have a go at hacking your uploads as well if you want (when you're done) ;)
Good idea - drop down menus and check boxes.
In the meantime I have a right newb question. At the moment on the register page I'm
using this

Code: Select all

 
mkdir("members/$id", 0755);
mkdir("members/$id"/images, 0755);
 
to make the user's "home" and images directories.
How can I then copy a file from the root (or maybe the "scripts" directory) into the new "images" folder ?

Best wishes
Monty
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Newb advice

Post by jackpf »

MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Re: Newb advice

Post by MiniMonty »

Sorted - cheers...

Best wishes
Monty
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Re: Newb advice

Post by MiniMonty »

OK, this is what I'm scratching my head about tonight...

The site is almost done but the "uploads" section (pretty important) is still awaiting attention.
I want the uploaded images to display in Flash (and I can do that) and I want them to display
both in the user's own gallery (got that working) AND in the various "section" galleries.

So my idea is this:
upload.php will have a script and a form. The form will have a list/menu drop down.
The user chooses an image then chooses which gallery to display it in from the drop down. The script uploads the image to
their "images" folder and numbers it incrementally. The script then (according to their choice from the drop down) opens a
.txt file in the appropriate folder (landscapes/portraits/travel etc) and appends the .txt file (which flash reads to display the images)
with the user id ($id) and the image number.

I think I have most of the functionality described above in the script below - but (big newb that I am)
I don't know 1) how to tell the script only to run once the user presses the "Submit" button and
2) how to use the drop down to tell the script which .txt file to open in which folder. (currently in the script as landscapes.txt)

All and any help much appreciated.

Best wishes
Monty

Code: Select all

 
<?php 
session_start(); 
     if(isset($_GET['id']) || isset($_POST['id']));
 
 else if (isset($_SESSION['id'])) {
 
    
     $id = $_SESSION['id'];
 
} else {
    // the page to send them to if they are NOT logged in
   include_once "index.php";
   exit();
}
?>
<?php
include 'uploads/doresize.php';
    define ("MAX_SIZE","100");
    function getExtension($str) {
    $i = strrpos($str,".");
        if (!$i) { return ""; }
        $l = strlen($str) - $i;
        $ext = substr($str,$i+1,$l);
    return $ext;
}
$errors=0;
        if(isset($_POST['Submit']))
        {
        $image=$_FILES['image']['name'];
        if ($image)
        {
        $filename = stripslashes($_FILES['image']['name']);
        $extension = getExtension($filename);
        $extension = strtolower($extension);
        
        if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
        {exit("Upload failed.<BR>Unacceptable file type.<br. Use only jpg, jpeg, png or fig formats");
        echo '<h1>Only try to upload .jpg, .jpeg, .png and .gif files!</h1>';
        $errors=1;
        }
    else
        {
        $size=filesize($_FILES['image']['tmp_name']);
        
        if ($size > MAX_SIZE*1024)
        {exit("Upload failed.<BR>Your file has exceeded the size limit of 220kb");
        echo '<h1>You have exceeded the size limit!</h1>';
        $errors=1;
        }
        
        $groovy = sizeof(glob("/members/$id/images/*"));
        $groovy = ++$groovy;
        print $groovy;
        $image_name=$groovy.'.'.$extension;
        $newname="".$image_name;
        $copied = copy($_FILES['image']['tmp_name'], $newname);
        if (!$copied)
        {
        echo '<h1>Copy unsuccessfull!</h1>';
        $errors=1;
        }
      }
     }
    }
if(isset($_POST['Submit']) && !$errors)
{
echo "<h1>File Uploaded Successfully!</h1>";
}
// NOW make the resize call!
img_resize ($_FILES [ 'image'] [ 'name'], $_FILES [ 'image'] [ 'tmp_name'], 537, $newname);
// Now make an array of the contents of the directory "landscapes"
$array = glob('members/$id/images/*');
// write the .txt file with the new array
$myFile = "landscapes.txt";
$fh = fopen($myFile, 'w+') or die("can't open file");
$stringData = "arse=images/".implode(",images/",$array);
fwrite($fh, $stringData);
fclose($fh);
// APPEND the .txt fil with the total image number
$myFile = "landscapes.txt";
$fh = fopen($myFile, 'a+') or die("can't open file");
$stringData = "&totalimgs=".$groovy;
fwrite($fh, $stringData);
fclose($fh);
?>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Member Upload</title>
<link href="styles/main.css" rel="stylesheet" type="text/css" />
<link rel="icon" href="http://www.shutterbugclub.com/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="http://www.shutterbugclub.com/favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 
</head>
 
<body>
<?php include_once "header_template.php"; ?>
<br>
<br>
<br>
<br>
<table width="975" height="366"  border="0" align="center">
  
    <td width="44%" height="328"><div align="center">
      <table width="100%" height="270"  border="0">
        <tr>
          <td height="322"><div align="center">
            <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="426" height="320">
              <param name="movie" value="images/required_site_pics/uploadBlurb.swf">
              <param name="quality" value="high">
              <embed src="images/required_site_pics/uploadBlurb.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="426" height="320"></embed>
            </object>
          </div></td>
        </tr>
      </table>
    </div>    </td>
    <td width="56%" rowspan="2">
    
    <div align="center"><?php include_once  "showpics.php"; ?></div></td>
  </tr>  <tr>
      <td height="32"><form action="" method="post" enctype="multipart/form-data" name="form1">
        <table width="70%"  border="0" align="center">
          <tr>
            <td><div align="center">
                <input name="file" type="file" size="0" maxlength="0">
            </div></td>
            <td><div align="center">
                <select name="select">
                  <option selected>Choose Gallery</option>
                  <option value="dayone">Day One Digital</option>
                  <option value="portraits">Portraits</option>
                  <option value="landscapes">Landscapes</option>
                  <option value="speed">Freeze it !</option>
                  <option value="events">I was there</option>
                  <option value="candid">Street / Candid</option>
                  <option value="travel">Far Far Away</option>
                </select>
            </div></td>
            <td><div align="center">
                <input type="submit" name="Submit" value="Go">
            </div></td>
          </tr>
        </table>
      </form></td>
    </tr>
</table>
<p>
  <?php include_once "footer_template.php"; ?>
</p>
<p>&nbsp;</p>
</body>
</html>
 
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Newb advice

Post by jackpf »

I think you should use a db for this tbh.

Like...what happens when the user deletes a photo?
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Re: Newb advice

Post by MiniMonty »

Interesting... never thought of that but as I get more and more to
grips with php and with myAdmin the whole db thing does seem to offer a
lot of possibilities.

So knowing the whole shape of the site as you do how would you conceive and design the db?
How would Flash (or any front end) pull the images from it ?
How would images attach to the user / uploader ?

OK - wrap it all up into one question - what does it all mean ? 8O

Best wishes
Monty
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Newb advice

Post by jackpf »

Well, personally, I would have one directory for uploads. I'd then have a record in the database for each photo, specifying what album it's in...who owns it...etc.

That way, they can be easily organised...easily deleted/managed etc...

That's just how I'd do it anyway. You could actually have a blob field as well, and store the image itself in the database. But...that could put a bit of strain on the db server if you have a lot of users.

And I'm afraid I don't know much about flash...so I can't help you there.
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Re: Newb advice

Post by MiniMonty »

jackpf wrote:Well, personally, I would have one directory for uploads. I'd then have a record in the database for each photo, specifying what album it's in...who owns it...etc.

That way, they can be easily organised...easily deleted/managed etc...

That's just how I'd do it anyway. You could actually have a blob field as well, and store the image itself in the database. But...that could put a bit of strain on the db server if you have a lot of users.

And I'm afraid I don't know much about flash...so I can't help you there.
This sounds like the best solution - but a headache to learn !
Have you got any good links to top tutorials (I need to get this done quickly).
Or do you fancy having your name on the site credits ???? :)

Best wishes
Monty
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Newb advice

Post by jackpf »

Lol. Umm...I'll have a look tonight if I have time.

Have you checked out tizag? They normally have some decent tutorials...


And lol. Just noticed - this is now my most active topic xD
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Newb advice

Post by jackpf »

Ok, here's the code I'd use. Obviously there are no visual elements...I'll leave that down to you ;)
And you might want to edit error messages, allowed formats, allowed galleries and so on. I've commented it all...so you should be able to figure it out.

But the basic code is there. It basically displays a form, and when the user submits the form, uploads the picture * it's details into the database. There are a couple of things you'll have to change, like how you get the user's username...your mysql details etc, but it should pretty much work :P

Oh, but yeah, read the comment about the error handling at the top...

Since I don't know...well, anything about how you coded your site, I've had to create my own error handler. If you do a similar sort of thing, you can easily integrate it into your own code though.

But yeah, post back if you have any problems...or whatever.

I also included a simple script demonstrating how to fetch the image from the database and display it.

So yeah, have fun :)

I put the table structure in comment somewhere btw.

Regards,
Jack.
Attachments
upload_pictures.zip
(2.28 KiB) Downloaded 34 times
Post Reply