Search
Left Quote    I have not failed. I've just found 10,000 ways that won't work.
- Thomas Alva Edison    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: file upload syntax questions
  This user is offline  lingh0e
  Subject: "file upload syntax questions" Posted: @ 4:19 pm on Apr 01 2007   

Member #: 291
Rank: User - (29)
Since: 03/03/07
Posts: 29
From: Ohio

I'm writing a basic file upload script, and I've hit a snag.

I want the user to be able to create their own directories, and let them upload to those directories. I'm having problems figuring out how to get the script to switch to that directory to when uploading the file.

I have www.host.com/ga llery/includes/ upload.php

It currently uploads everything to the /includes dir. I want it to upload the files to

www.host.com/ga llery/user

but I can't seem to get it to recurse to the user dir. All I get are errors.

I've tried lots of different methods and they all give me errors.

Anyone have any suggestions?


Feel free to kick me if I get annoying
    Viewed: 13,204 Times | Reply to This | To top
  This user is offline  ki
  Subject: "re: file upload syntax questions" Posted: @ 6:42 pm on Apr 01 2007    

Member #: 204
Rank: User - (50)
Since: 09/16/06
Posts: 53
From: Florida

give some script so we can see the error




woohoo!

    Viewed: 13,196 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: file upload syntax questions" Posted: @ 7:18 pm on Apr 02 2007    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

Can't you just specify the path based on the username (insert the username variable as the name for the folder) whenever you move_uploaded_f ile()?


Code:


$uploaddir = $_SERVER['DOCU MENT_ROOT'].& quot;/gallery/ ".$usernam e."/&quo t;;

//Copy the file to the location...
if(move_uploade d_file($_FILES[ "userfile "][" ;tmp_name" ;], $uploaddir)) {
echo "File uploaded!" ;;
} else {
echo "There was a problem when uploding the new file.";
print_r($_FILES ); //displays variable info.
}



edit: Also, if they want to create a directory, just use the directory name as a text field on a form. Run it through the junk array so you don't allow crap and weed out potential errors. Then use mkdir to create the directory... and when you move_uploaded_f ile tack on the variable for the directory they want onto your $uploaddir.



Edited at 07:28:33 pm on 04/02/07


-bs0d | AllSyntax.com

    Viewed: 13,178 Times | Reply to This | To top
  This user is offline  lingh0e
  Subject: "re: file upload syntax questions" Posted: @ 4:31 am on Apr 03 2007    

Member #: 291
Rank: User - (29)
Since: 03/03/07
Posts: 29
From: Ohio


Code:

$uploaddir = $_SERVER['DOCU MENT_ROOT'].& quot;/gallery/ ".$usernam e."/&quo t;;



That's pretty much what I have, only I forgot the periods around the variable. It'll go to the "gallery " folder but it wouldn't go any further than that, totally ignoring the fact that I even put the variable in there. I'll give it a try.




Feel free to kick me if I get annoying

    Viewed: 13,169 Times | Reply to This | To top
  This user is offline  lingh0e
  Subject: "re: file upload syntax questions" Posted: @ 9:13 pm on Apr 03 2007    

Member #: 291
Rank: User - (29)
Since: 03/03/07
Posts: 29
From: Ohio

Success!!

Thanks again for the help!




Feel free to kick me if I get annoying

    Viewed: 13,161 Times | Reply to This | To top
  This user is offline  ki
  Subject: "re: file upload syntax questions" Posted: @ 12:40 pm on Apr 05 2007    

Member #: 204
Rank: User - (50)
Since: 09/16/06
Posts: 53
From: Florida

hmmmm I use copy for moving mine O_O but im on a unix server




woohoo!

    Viewed: 13,135 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank