Page 3 of 4
Posted: Tue Mar 23, 2004 8:10 am
by Wayne
I am a little bit confused by why you need to know how to specify the location of the file on the local machine .... heres how it works, you click on the button next to your file upload and you browse for the file(s), once you have selected the file(s) and completed the rest of the form you submit it. When you submit the form the files are uploaded to your server and stored in a temporary folder, this is where the temp name associated with file uploads comes in. You then move the file from the temp folder to where you want it to be by using
Code: Select all
move_uploaded_file($_FILES['photo1_upload']['tmp_name'], $nameandpathyouwantfiletobe);
etc. The php script never touches the local machine, that is not possible!! There is a difference between what happens server side and what happens client side, I hope that clears things up.
Posted: Tue Mar 23, 2004 8:11 am
by mjseaden
Hi microrobot
I did read your posts - yesterday I tried changing the permissions on the upload directory, however it gave me the error I stated after I changed them. I assumed that the / slashes were correct because I found the empty file in the target directory they were referring to.
I'm just trying the image code - it seems to take an age to load up the page when I click on the upload photos button, which I take it means it is currently uploading the file. I'll take a look at the server when it seems to have finished (or try a smaller file next time..)
Thanks
Mark
Posted: Tue Mar 23, 2004 8:15 am
by magicrobotmonkey
can you manually ftp from/to that location?
Posted: Tue Mar 23, 2004 8:16 am
by mjseaden
I'm not sure what the new upload code is doing. When I click on the upload photos button on the form, it seems to be doing some activity, but it never loads the page. Rather, the progress indicator at the bottom of my IE window gradually gets to 100%, where it remains. This seems to happen no matter what the size of file I put into photo1_upload.
Posted: Tue Mar 23, 2004 8:17 am
by mjseaden
Yes I can manually upload
Posted: Tue Mar 23, 2004 8:19 am
by magicrobotmonkey
can you look at your ftp log either locally or on the server?
Posted: Tue Mar 23, 2004 8:27 am
by mjseaden
Yes but I'm just going to try and get hold of a good log file interpreter so I can make sense of it. Admittedly I can't see any sign of files being uploaded so far.
Posted: Tue Mar 23, 2004 8:40 am
by mjseaden
magic - I've looked at the log file and I don't think there's been any uploading activity.
Posted: Tue Mar 23, 2004 9:14 am
by magicrobotmonkey
which one on your machine or on the server?
Posted: Tue Mar 23, 2004 9:57 am
by mjseaden
magic, I've tried this code now, and I appear to be at least getting somewhere:
Code: Select all
$conn = ftp_connect("$host");
if(!$conn)
{
echo 'Error: could not connect to FTP server. Please try again later.';
exit();
}
echo "Connect to $host.<br />";
// log in to host
@ $result = ftp_login($conn, $user, $pass);
if(!$result)
{
echo "Error: Could not log on as $user<br />";
ftp_quit($conn);
exit();
}
echo "Logged in as $user.";
echo "Uploading file:";
$filename = $_FILES['photo1_upload']['name'];
echo $filename;
if(!$success = ftp_put($conn, '/tmp/test.mp3', $filename, FTP_BINARY))
{
echo 'Error: Could not upload file to server';
ftp_quit($conn);
exit();
}
echo 'File uploaded successfully';
ftp_quit($conn);
However, it's still giving me the unsuccessful upload message. I've changed the FORM on the previous page to include ENCTYPE="multipart/form-data" (this was probably a major source of problem previously).
Posted: Tue Mar 23, 2004 10:04 am
by ol4pr0
Code: Select all
// not sure however are you still using
move_uploaded_file() ?
might wanna try @copy
Posted: Tue Mar 23, 2004 10:16 am
by mjseaden
I CAN'T GET IT TO WORK!!!! WHY IS IT SO DIFFICULT TO DO THE SIMPLEST OF THINGS AS TO UPLOAD A FILE FROM THE USER'S MACHINE AS THEY HAVE SELECTED VIA A FILE OBJECT AND THEN UPLOAD IT TO MY SITE'S FTP!!!??? WHAT IS GOING ON!! ARRRGHH!!!
Posted: Tue Mar 23, 2004 10:34 am
by ol4pr0
Code: Select all
if(!$success = ftp_fput($conn, '/tmp/test.mp3', $filename, FTP_BINARY))
//try the ftp_fput() instead of ftp_put()
Posted: Tue Mar 23, 2004 10:43 am
by ol4pr0
Or try something simple like this.. to make sure its not youre code thats messing it up.
Code: Select all
// code can be found on http://www.zend.com
<?php
$file = 'somefile.txt';
$remote_file = 'readme.txt';
$ftp_server = ' ';
$ftp_user_name = ' ';
$ftp_user_pass = ' ';
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
// close the connection
ftp_close($conn_id);
?>
Posted: Tue Mar 23, 2004 10:44 am
by mjseaden
Hi ol4pr0
I think the problem is that what I'm asking it to do is in fact impossible - I don't think PHP can access the local machine's files in this way.
On top of this, I'm now changing the method to using the FILE-POST method and then using move_upload. This should work, all it will mean is a rearrangement of my form into two distinct pieces rather than a single one.
Web dev is might frustrating at times, especially for a file upload/download newbie!