5 Replies - 1808 Views - Last Post: 02 September 2008 - 03:31 PM Rate Topic: -----

#1 Sonastylol  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 151
  • Joined: 15-December 07

File Portal

Posted 01 September 2008 - 05:30 PM

Hey guys,

Im trying to code something like the Newgrounds.com File Portal.

I already have registration, login, image uploading, and a mock-up profile(merely for checking stats more than anything), but I have some issues.

As of right now, the file gets uploaded directly to /uploads/yourimagename.ext, then the user's submission variable gets incremented and updated to the database using this (segment) of code:


if (copy($_FILES['file']['tmp_name'], $imgurl)) {
				echo('Your file was succesfully uploaded.  Here is the URL to the file:  <a href="'.$imgurl.'">here</a><br/>');
				echo('<a href="/test.php">Your Profile</a>');
				//add 1 to user submissions
				$_SESSION['submissions']++;
				//replace submission count in database
				mysql_query("UPDATE `users` SET `submissions` = '$_SESSION[submissions]' WHERE `id` = '$_SESSION[id]'");




Again, this works PERFECTLY. Even when you load the test.php profile page, the submission is shown as incremented, and the database as well is incremented. This is no good, though.

What I want is to create ONE template frame, which loads the photo into it dynamically. Keeping track of the link isnt that important once the photo is uploaded, because it will be entered into the user's profile page immediately, as well as stored in a database.

The table for the images will look like this.

image_id | user_id | name | MAYBE_CATEGORY--NOT SURE YET

This ensures that the image is always linked to a USER ID, in case the user changes their username at any point (the user table is already designed like this, using both username AND id.

So my question is. How do I get a page (ONE PAGE) to load this image in the center(or wherever I want). An example would be domain.com/images.php?id=1 for the first ever image uploaded. Something like this.

I will have to design the portal after this, but I would like to know how to do this first. After that, I can TRY to design a front page table that shows the last 10 photos uploaded.

Thank you very much, Dream In Code.

If you need to see more of my code, Id be glad to show it, but privately. This is NOT for personal use.


Is This A Good Question/Topic? 0
  • +

Replies To: File Portal

#2 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: File Portal

Posted 01 September 2008 - 05:38 PM

you would have to query the database for the images id/filename. You would then upload the filename to an <img> tag.

So: <img src="<?php echo $location>"/>
Was This Post Helpful? 0
  • +
  • -

#3 Sonastylol  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 151
  • Joined: 15-December 07

Re: File Portal

Posted 01 September 2008 - 08:03 PM

View PostJBrace1990, on 1 Sep, 2008 - 05:38 PM, said:

you would have to query the database for the images id/filename. You would then upload the filename to an <img> tag.

So: <img src="<?php echo $location>"/>



Ive been reading about $_GET, wouldnt I have to use that?

SOMEHOW, I dont know how yet, but I know that it is SOMEHOW possible to, in the case of domain.com/imageportal/viewimg.php?id=###

to take that number, and have it load through a SELECT mysql query the information.

using a table such as
img_id | user_id | img_name | img_desc | img_views | img_votes | img_score

to place the data onto the page.

Is there a tutorial for somethign like this? Your post was informative but very short and I would love more info if it is available.

Thanks a lot
Was This Post Helpful? 0
  • +
  • -

#4 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: File Portal

Posted 01 September 2008 - 10:44 PM

yes, just assign this:

$location = mysql_real_escape_string($_GET['id']);


basically, yes, you can query the database with $location for either the ID of the image (most probable), or name, or anything... then just return the results and put the mysql_fetch_array into the image location... you should probably store the relative path of the images, IE: images/user_uploads/sHHEBjhd.jpg... I would suggest encrypting the filenames, possibly even MD5ing them as well to prevent multiple files with the same name... that, or attach the uploading users username to the filename...

then you would go with: <img src="http://mysite.com/<?php echo $location; ?>">

and end up with: <img src="http://mysite.com/images/user_uploads/sHHEBjhd.jpg">

This post has been edited by JBrace1990: 01 September 2008 - 10:49 PM

Was This Post Helpful? 0
  • +
  • -

#5 Sonastylol  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 151
  • Joined: 15-December 07

Re: File Portal

Posted 02 September 2008 - 02:15 PM

Thanks a lot Jbrace.

I have a question tho, not really ethical but... situational.

What would you do in my situation?

I dont understand why I need to do anything fancy with file names at all...


Basically -- Since I am going to be referring to the images from the URL by their ID, I SHOULD be able to save the image as 1.jpg, 2.jpg, 3.gif, etc..

At least then every user of the site knows how many have been uploaded anyway :)

Is a pattern like this bad?

Is it better to make it so someone must USE the site, and not just randomly type in 1, 2, 3 etc? I'll still have an $img_name spot in my table to display the images name ABOVE the image itself ( for viewing purposes ONLY )
Was This Post Helpful? 0
  • +
  • -

#6 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: File Portal

Posted 02 September 2008 - 03:31 PM

make some kind of hashing or encryption function to the filename. IE: append their username to the filename, add the image ID to the end of the filename, base64 encode it, then MD5 that result.

You'll end up with a 32 bit filename, and i doubt any collisions...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1