PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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
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.
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..)
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.
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.
$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).
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!!!
// 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);
?>
Last edited by ol4pr0 on Tue Mar 23, 2004 10:47 am, edited 1 time in total.
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!