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