Hi,
I am using your code to send files to another server which is sending the files fine but they are 0kb when they are uploaded. Do you have any idea why they would be 0kb and not what they was uploaded as.
Cheers,
Adam
» PHP Forum Archive » Web Developer Tutorials » Discuss our Web Development Tutorials
Hi,
I am using your code to send files to another server which is sending the files fine but they are 0kb when they are uploaded. Do you have any idea why they would be 0kb and not what they was uploaded as.
Cheers,
Adam
Hi Adam,
do you checked the permissions for the upload directories?
has the remote ftp user enough rights?
Hi! I have the same problem as Adam. When I upload my file via cURL to the server, the file will be in the temporary directory in the 'tmp_name'. But I don't have permission to the temp directory. I would have to copy the temp file to the right place, where I can see only the good filename with 0 kb filesize. If I move it with move_uploaded_file(), it is a PHP function, and it doesn't work above the limit in php.ini. What can I do?
Thanks!
Hi Medpress,
you understand that this upload works like:
1. file send from the browser to the web server (the file is stored in upload temp folder as all uploads)
2. from your web server the file is send using cURL to the ftp location.
You see that "ftp upload" is done by the web server. Do you tried to send a local file (without uploading) to remote ftp location?
Hi Olaf,
yes I do. I use this code:
if (isset($_POST['Submit'])) {
if (!empty($_FILES['feltoltendo']['tmp_name'])) {
$ch = curl_init();
$cel="./new_file.eps";
$localfile = $_FILES['upload']['name'];
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_URL, 'ftp://ftp_usr_name:passw@ftp_server/filecenter/new_file.eps');
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_exec ($ch);
$error_no = curl_errno($ch);
curl_close ($ch);
if ($error_no == 0) {
$error = 'File uploaded succesfully.';
// if(!move_uploaded_file($_FILES['feltoltendo']['tmp_name'], $cel)) print("Error moving file to new file<BR>");
// if I don't use this line above, the size of the target file will be 0kb
} else {
$error = 'File upload error.';
}
} else {
$error = 'Please select a file.';
}
}
The output is: "'File uploaded succesfully." if the size of file is <2MB, else "'File uploaded succesfully.Error moving file to new file".
Thanks
Ok I see you need to raise the max. upload file size
I can't raise the max. upload file size, that's why I have to use the ftp file upload.
The code above doesn't work under 2 Mb well without the move_uploaded_file().
If you can't raise the max upload size, you need to use a FTP client for upload.
Do you tried this setting inside a .htaccess file?
php_value upload_max_filesize 15M
There are two different questions: 1. with the code above I can't upload any file. The output is: "'File uploaded succesfully.", but the size of the file is 0kB.
2. The user wanted to use only the web browser for the upload, and wanted to upload files with size of 8-10 Mb. The administrator on the server set the upload_max_filesize to 4M, but it isn't enough. He said, that I have to use something in the PHP code to upload the files using FTP, because there isn't any limit. I thought good to use the cURL, but it doesn't work.
What can I do?
A web based upload is always limited to the max upload size, because the upload is processed by the web server and not the ftp server.
The curl/ftp function is used to send the file from your web server to another ftp server (this might be the same server too).
do you tried the php_value setting in your .htaccess file?
The .htaccess files can't run on the server.
Why is the size of the file 0 kB?
Quote from: medpress"The .htaccess files can't run on the server.
Why is the size of the file 0 kB?"
It's just an empty files created by the curl function.
I'm sorry you can't upload bigger from a browser if you haven't access to the php upload configuration.
Maybe you can upload host file on some remote image hosting service? Or use a REAL web host. A great shared hosting provider is WebFaction.
Hi Olaf,
ok, I can't upload bigger, but why can't upload smaller? Why doesn't work the code above?