Complicated file upload problem
Posted: Sat Apr 23, 2005 7:48 pm
Hello, I am trying to do something that seems like it should be fairly simple and is turning out to be totally impossible.
I have a site that is hosted, not by me, but by a hosting company: i.e. I have no server access whatsoever. I want to make a page that allows someone to upload an image to be stored in my public_html on the hosting company's server.
I tried to do this via $_FILES, but it does not work, as the place where the image is successfully uploaded to temporarily is a place that I am not allowed to copy from. That is, when using $_FILES, my uploaded file goes to /var/tmp/ and when I do a move_uploaded_file() it gives me a Permission Denied error.
The first thing I tried was using ini_set to set upload_tmp_dir, but this did not work (I'm sure the hosting company doesn't allow those privileges). The second thing I tried was creating an .htaccess file in my public_html that said the following:
This also did not work. (Is the .htaccess supposed to be in the document root or in the folder that you want to become upload_tmp_dir?)
Nonplussed, I decided to try to use FTP instead of $_FILES.
I have, in short, some code that results in looking like this:
Now this does not work either. I get 'FTP Upload has failed!' I am assuming that the problem is that as PHP and FTP are both running on the same server (that is, my hosting company's server), PHP is looking for the source file, C:/Temp/sourcefile.jpg on the server that PHP is running on, and not on my local machine, where the source file is actually located. If this is so, what do I do? Does this mean that all of the PHP FTP functions do not work at all unless you are running PHP on the same server that you are uploading the files from? That doesn't make sense because then you could just copy the file using the file system and you wouldn't need FTP.
How do I make it so that FTP, even though called by PHP running on a server that is NOT the machine I am trying to upload a file from, knows how to find the file on my local machine?
I'm so confused!
Thanks,
Elise
I have a site that is hosted, not by me, but by a hosting company: i.e. I have no server access whatsoever. I want to make a page that allows someone to upload an image to be stored in my public_html on the hosting company's server.
I tried to do this via $_FILES, but it does not work, as the place where the image is successfully uploaded to temporarily is a place that I am not allowed to copy from. That is, when using $_FILES, my uploaded file goes to /var/tmp/ and when I do a move_uploaded_file() it gives me a Permission Denied error.
The first thing I tried was using ini_set to set upload_tmp_dir, but this did not work (I'm sure the hosting company doesn't allow those privileges). The second thing I tried was creating an .htaccess file in my public_html that said the following:
Code: Select all
php_value upload_tmp_dir /home/hearchri/public_html/Model/Book/book_images/large_images/This also did not work. (Is the .htaccess supposed to be in the document root or in the folder that you want to become upload_tmp_dir?)
Nonplussed, I decided to try to use FTP instead of $_FILES.
I have, in short, some code that results in looking like this:
Code: Select all
$source_file = "C:/Temp/sourcefile.jpg";
$destination_file = "destfile.jpg";
ftp_file($source_file, $destination_file);
/* FUNCTION (in included file) */
function ftp_file($source_file, $destination_file) {
$conn_id = ftp_connect('ftp.server.com');
$login_result = ftp_login($conn_id, 'username', 'password');
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed! ";
exit;
}
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
if (!$upload) {
echo "FTP upload has failed!<br>";
}
ftp_close($conn_id);
}How do I make it so that FTP, even though called by PHP running on a server that is NOT the machine I am trying to upload a file from, knows how to find the file on my local machine?
I'm so confused!
Thanks,
Elise