![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
I just don't get it, whatever happened to simplicity?
I have the php5 and MySQL Bible as well as PHP fast and easy web development. These books are great for the most part, that's how I get started in anything. I am working on a project here that requires a member (user) to be able to upload their picture so that it can be displaid in their profile. It should be easy enough, or so I thought. Everything that I have found about how to do this, just is not working the way it should. So, I get on the web to look some more, and all the tutorials that I have seen, only reflect the same methods as the book do. Everything in these books so far only explain how to use fopen() as a way to ftp into the site and write to or read from an existing document (that is of course unless I am missing something). There is another way that requires uploading to a temp directory then moving the temp file to the folder that you want to move it to. My hosting service plan does not allow me to use this method. So here is what I need to do, The user is logged into the system allready and is trying to upload a file. I need that file to be uploaded into the image directory directly, without having to move it from a temp folder at all, but I do need to automaticly give the file a number name and leave it's extension. The number name should be incrimental, based on the images that allready exhist. Then this file name should be entered into the database so that I can call it in the user's profile page. Any suggestions on how to do this? Thanks Mike
__________________
Here's my latest project still in the works, and I need to get rid of this "frame" situation for real. www.prideofaustin.com |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Oct 2004
Location: England, UK
Posts: 139
Rep Power: 0
![]() |
The file upload form is quite easy and the incremented file name is cake, but unless your server allows the temp directory to upload to im not sure how to do it.
Are you sure your server doesn't allow it or do you just need to edit your php.ini file?
__________________
Don't wound what you can't kill |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() |
I ran in to a simular problem. I ended having to read the file with php and then copy it to a different dir for it to stay on the server. Otherwise it just get's uploaded to your tmp dir and then deleted as soon as the script is done running.
the functions you need to use to do this are: fopen fread fwrite Good luck.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#4 |
|
Programmer
|
Ade,
this isn't my home server, so I have no access to php.ini, I am hosted at godaddy and I am on a tight budget, with the lowest plan. I actually called tech support to see what was up with all of this, and they said, that in order to copy something from the temp directory to the directory that I need it to go to, I have to upgrade my subscription. I am beginning to hate webhosting. I mean, they can easily make a killing by just giving you the ability to do anything you want for the lower price but they want you to pay more for more allowances... lol.. frustration. Pizentios, I am aware of the fopen, fwrite, fread functions, and I may have just been reading it wrong, because I can't seem to get them to work with what I am doing. So, I am going to look at the sites you linked to to see if they help. My impression of what they do is that they let you read and write to a file. I assume I should just try writing to a directory instead of a file. Thanks a lot for the help guys. Mike
__________________
Here's my latest project still in the works, and I need to get rid of this "frame" situation for real. www.prideofaustin.com |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Sep 2004
Posts: 207
Rep Power: 5
![]() |
Can you still set the tmp_dir? I looked at a tutorial where you could but it was mighty old. Anyway if you can...
When you talked to your host and said a temp directory they probably though one of the servers stupid Temporary_Files folders or something like that. The reason your probably coudn't do that is you don't have acces to it, but if you set the tmp_dir to a folder you do have access to such as any folder you seen in your ftp when you connect to it you should be fine. So try setting the tmp_dir to the folder you want the file in and then just use the move command and move it into that folder. Tell me if it works too. ![]() Meh 2 cents is in!
__________________
_______________________________ BlazingWolf |
|
|
|
|
|
#6 |
|
Programmer
|
Blazing Wolf,
Now that is an initeresting idea, setting the temp directory someplace within where I have access. I only have access to anything folder or file that is within my root, and of course folders and files within those folders, but anything before the root, I have no access. I am going to attempt to use the fopen information that was given here, but it is my understanding that this can leave me open to a few security risks. Hmm, I am not sure how to change my temp directory, but, I will look that all up with my host, or at least try to get with them on how to do it. I would assume that there is a way to do that with mysql? but like I said, I am new to this stage of the game. So far, any of the questions that I have asked on here have been answered pretty well. Many great people here have been so helpful, I wish I could find a way to thank them all. thanks Mike
__________________
Here's my latest project still in the works, and I need to get rid of this "frame" situation for real. www.prideofaustin.com |
|
|
|
|
|
#7 |
|
Programmer
|
Oh crazy,
I haven't seen this before. It is all part of this same journey so, I am just tacking it to this thread. I have noticed a few times where the = sign is used and I am understanding that = translates to "is" as in $dog = $_POST('img') meaning, from here on in wherever I type $dog, assume that I am talking about the posted img. I have also noticed at times we use == Wich, I assume means is equil to as in numerical units or something like that. In looking at the fwrite function given, I am seeing === like so if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}lol Thanks again for all everyone's help Mike
__________________
Here's my latest project still in the works, and I need to get rid of this "frame" situation for real. www.prideofaustin.com |
|
|
|
|
|
#8 |
|
Programmer
|
I really have no clue if there was some logical conclusion that got me here but, I was able to figure out how to do this, using the copy function and ftp upload. I didn't need fopen fwrite, or anything like that. I am going to show you the coding that I used, it's a bit sloppy, but I did need a way to actually see the information, thus the html and echo statements and renamed $stuff.
<?
$upd = 'ftp://username:password@mydomainftpprotocol.com/directory/';
if ($_FILES[upload] !="") {
@copy($_FILES[upload][tmp_name], "$upd".$_FILES[upload][name]) or die("could not copy the file.");
} else {
die("no input file specidied");
}
$temp = $_FILES[upload][tmp_name];
$name = $_FILES[upload][name];
$size = $_FILES[upload][size];
$type = $_FILES[upload][type];
?><html><head><title>uploaded</title></head>
<body><p>
temp: <? echo $temp; ?><br>
Name: <? echo $name; ?><br>
Size: <? echo $size; ?><br>
type <? echo $type; ?><br>
</p></body></html>So, for anyone who needs an explination, my upload form used the name="upload" attribut, so anywhere that you see upload in the code it refers to the file itself. $upd is of course usually the directory that you want it to go to, it's usually "/usr/local/bin/" but, I decided to use my ftp protocol instead, just to see what would happen, and violin, it worked. Trial and error is great, I am just glad I didn't mess anything up while doing it, lol. This image is part of a profile situation, so, the next thing that I am going to need to do is, reasign a name to the image. What I will do, is, since each user, or member, only has 1 screenname, and is only allowed 1 picture, I will rename the image based on the username, and the file extention. I of course will only allow certain file types, jpg and gif, as there are no techies that would be members who might use png or other image types. Once the file is renamed, I will then place that image name into the database added to the user's profile record, so that it will be easily called within the profile page. I pretty much know how to do all of that stuff, so, if I get stumped I will ask, but, once I am done, I will add them here so that those that might be curious about how to do it, have that information. Thanks to all in this thread who have pointed me in the right direction here. p.s. If anyone can see any reason why I should seak another method of doing this, like security risks or anything, please let me know. I would hate to leave myself open to some kind of risk. Thanks Mike
__________________
Here's my latest project still in the works, and I need to get rid of this "frame" situation for real. www.prideofaustin.com |
|
|
|
|
|
#9 | |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|