Jump to content


image


9 replies to this topic

#1 pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 14 August 2006 - 03:40 AM

I just searched this, there was one page of unrelated crap. :\
I have seen in the past things on image uploading, it was all really long scripts to do this one thing, I was wondering if there's an easier way?
Specifically what i'm wanting to do is upload an image and have it be renamed with the id of the specific thing.
like let's say the id it's for the specific mysql insertion is 165 then I want the image to be renamed from jimmy5432firstpicture.gif to 165.gif.
Thanks.

#2 Wybe

    Jedi In Training

  • Members
  • PipPip
  • 399 posts
  • Gender:Male
  • Location:the Netherlands
  • Interests:Graphic design, digital and traditional, street style, graffiti, guerilla drawing, typography, coding, sex

Posted 14 August 2006 - 04:07 AM

Not too hard, but you'll have to dig trough the longer pieces of code because they usually give you some protection against all the shit your end-users might saddle you up with (eg. wrong file types, too large file sizes, this and that).

I wrote a tutorial that may come in handy for you since it doesn't have too much rubarb woven trough it (a lot of explanation though).

Mind you, when you get to the function "move_uploaded_file()", the first argument is the temporary file, and the second argument decides where it will be uploaded to and what the file will be called, hence you could insert your $id here and it'll be allright.

Anyway, my tutorial is offline but I found it in google's cache for you. If you have any questions after you've read it, just ask: wybe@hotmail.com

Google's cache:
http://66.249.93.104/search?q=cache:UWhjrw...lient=firefox-a

#3 pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 14 August 2006 - 04:14 AM

Thank you!
Most of these are like a 80 lines long and there's no explenation of it.
:) you rock

#4 Wybe

    Jedi In Training

  • Members
  • PipPip
  • 399 posts
  • Gender:Male
  • Location:the Netherlands
  • Interests:Graphic design, digital and traditional, street style, graffiti, guerilla drawing, typography, coding, sex

Posted 14 August 2006 - 01:27 PM

glad to be of help! i appreciate the thank you and that's what i do it for :laugh:

Edited by Wybe, 14 August 2006 - 01:28 PM.


#5 pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 14 August 2006 - 07:47 PM

Crap, i'm having troubles with this. :(
I got it to upload them, now i'm trying to get the renaming.
if($file_uploaded!="failed") {
if (move_uploaded_file($_FILES["image"]["tmp_name"], $upload_dir.$_FILES["image"]["name"])) {
echo '<a href="'.$upload_dir.$_FILES["image"]["name"].'">' .$_FILES["image"].'</a> uploaded.'

In this, I need to change
$upload_dir.$_FILES["image"]["name"])) {
that line right?
I haven't figured out what to change in it.
I've tried a few different things, most recently
$upload_dir.$_POST["id"],$_FILES["name"])) {
but i'm not getting anything to work. :\

#6 Wybe

    Jedi In Training

  • Members
  • PipPip
  • 399 posts
  • Gender:Male
  • Location:the Netherlands
  • Interests:Graphic design, digital and traditional, street style, graffiti, guerilla drawing, typography, coding, sex

Posted 14 August 2006 - 08:09 PM

View Posttgs, on Aug 15 2006, 02:47 AM, said:

In this, I need to change
$upload_dir.$_FILES["image"]["name"])) {
that line right?
I haven't figured out what to change in it.
I've tried a few different things, most recently
$upload_dir.$_POST["id"],$_FILES["name"])) {
but i'm not getting anything to work. :\

That line, indeed, but it doesnt work probably because you've got a comma between $_POST["id"] and $_FILES["name"], it should probably be a dot because you're musn't make athird argument in the function. You are editing the right line though. Also, you need to keep in mind the extention you want the filename to have!


Wybe

#7 pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 14 August 2006 - 08:26 PM

Thank you. That didn't work either but i'll figure it out, I hope.

Edit: Actually, this is giving me all hell. :(
Sorry to have to continue this, could I get some more advice on this...
This seems like it should be simple, i'm positive that it is!
I'm getting Array instead of actual values. I can't think of what to do.

Edited by tgs, 14 August 2006 - 11:09 PM.


#8 Wybe

    Jedi In Training

  • Members
  • PipPip
  • 399 posts
  • Gender:Male
  • Location:the Netherlands
  • Interests:Graphic design, digital and traditional, street style, graffiti, guerilla drawing, typography, coding, sex

Posted 15 August 2006 - 04:19 AM

could you give me the snippet of code you've used and i assume it only says "Array" instead of some error, right?

Check if any of the values you've used is an array, if so you'll have to figure out why. It could be somewhere deep inside your code unfortunately.

#9 pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 15 August 2006 - 04:22 AM

I'm thinking that there's a conflict with using the other parts of my code inside the function.
I've shown you the code, I changed to to the period. and it gives me Array.

#10 Wybe

    Jedi In Training

  • Members
  • PipPip
  • 399 posts
  • Gender:Male
  • Location:the Netherlands
  • Interests:Graphic design, digital and traditional, street style, graffiti, guerilla drawing, typography, coding, sex

Posted 15 August 2006 - 11:12 AM

Then all I can do now is tell you to find out what variable is an array and why





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users