mme Posted December 14, 2010 Share Posted December 14, 2010 Hi, I am trying upload files to a remote server using CURL however It is not sending all the values in the array. $auth_local='testing123'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $auth_remote_url[$auth_no] ); curl_setopt($ch, CURLOPT_POST, TRUE); $post_array = array( "auth"=>$auth_local, "auth_e"=>$auth_e, "my_file"=>"@".$myfile, "md5"=>$md5, "check"=>"0", "upload"=>"Upload"); curl_setopt($ch, CURLOPT_USERAGENT, "Test Upload"); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $response = curl_exec($ch ); curl_close($ch ); When I check the value of $_POST['auth'] it is blank. When I remove "my_file"=>"@".$myfile, It does read the correct value Why is this not returning a value? Thanks, mme Quote Link to comment Share on other sites More sharing options...
jdavidbakr Posted December 14, 2010 Share Posted December 14, 2010 What's the value of $myfile? Quote Link to comment Share on other sites More sharing options...
mme Posted December 14, 2010 Author Share Posted December 14, 2010 What's the value of $myfile? $myfile=$_FILES['uploaded_file']['tmp_name']; Quote Link to comment Share on other sites More sharing options...
jdavidbakr Posted December 14, 2010 Share Posted December 14, 2010 What's the value of $myfile? $myfile=$_FILES['uploaded_file']['tmp_name']; What is the remote server going to do with that? Just trying to figure out why that's a parameter, since it's a local file that the remote server can't do anything with. My guess is that there's something that's messing up the post data between the '@' symbol an the file name, like an invalid character; unfortunately I'm really not too familiar with CURL. Quote Link to comment Share on other sites More sharing options...
mme Posted December 14, 2010 Author Share Posted December 14, 2010 What's the value of $myfile? $myfile=$_FILES['uploaded_file']['tmp_name']; What is the remote server going to do with that? Just trying to figure out why that's a parameter, since it's a local file that the remote server can't do anything with. My guess is that there's something that's messing up the post data between the '@' symbol an the file name, like an invalid character; unfortunately I'm really not too familiar with CURL. Thanks for your quick reply, Basically what it is doing is sending the uploaded file to another server which processes the $_POST['my_file'] variable as a file upload and stores the file on the server. if (!empty($_FILES['my_file'])) { move_uploaded_file($_FILES['my_file']['tmp_name'],$filename); } Hope that helps, Thanks, -mme Quote Link to comment Share on other sites More sharing options...
jdavidbakr Posted December 14, 2010 Share Posted December 14, 2010 Hm, ok, I just looked up the curl_setopt() command and it appears that you're doing it correctly. Two thoughts: 1) Are you sure there's an uploaded file? Maybe do a var dump of $post_array to make sure that $myfile is defined. 2) Maybe the file size is too big and is being rejected by the destination server? Quote Link to comment Share on other sites More sharing options...
schilly Posted December 14, 2010 Share Posted December 14, 2010 jdavidbakr is right. I think you're confusing the file name with file data. Sending $_FILES['uploaded_file']['tmp_name'] via POST variable my_file will just give the temporary location of that uploaded file on the local server. The data of that file will still be on the local server so you will have no data to save on the remote server. I think you need to use CURLOPT_INFILE and pass the file data into that. Check http://php.net/manual/en/function.curl-setopt.php. I've never tried to do this before so not positive on the steps you need to take to do it. Quote Link to comment Share on other sites More sharing options...
mme Posted December 14, 2010 Author Share Posted December 14, 2010 Thanks for your quick reply's, jdavidbakr is right. I think you're confusing the file name with file data. Sending $_FILES['uploaded_file']['tmp_name'] via POST variable my_file will just give the temporary location of that uploaded file on the local server. The data of that file will still be on the local server so you will have no data to save on the remote server. I think you need to use CURLOPT_INFILE and pass the file data into that. Check http://php.net/manual/en/function.curl-setopt.php. I've never tried to do this before so not positive on the steps you need to take to do it. Hmm I just tried it with a smaller file which seemed to work without any problems. However It seems to get errors with larger files (2MB). Is there a limit as to how big an array value can be to post? Hm, ok, I just looked up the curl_setopt() command and it appears that you're doing it correctly. Two thoughts: 1) Are you sure there's an uploaded file? Maybe do a var dump of $post_array to make sure that $myfile is defined. 2) Maybe the file size is too big and is being rejected by the destination server? 1. It seems to work with smaller files 2. According to my host it has a max filesize of 10MB Quote Link to comment Share on other sites More sharing options...
schilly Posted December 14, 2010 Share Posted December 14, 2010 do phpinfo() on the remote server and look at the upload_max_filesize and post_max_size vars. you may be able to up these via ini_set('upload_max_filesize','10M'); etc or else use htaccess to do it. Quote Link to comment Share on other sites More sharing options...
mme Posted December 14, 2010 Author Share Posted December 14, 2010 do phpinfo() on the remote server and look at the upload_max_filesize and post_max_size vars. you may be able to up these via ini_set('upload_max_filesize','10M'); etc or else use htaccess to do it. Thanks, I have figured out what the problem is. post_max_size : 2M Is there any way to increase this? EDIT: already tried this but it does not seem to have any effect: Top of the page. ini_set('post_max_size','10M'); And also in my .htaccess php_value post_max_size 20M Thanks, -mme Quote Link to comment Share on other sites More sharing options...
schilly Posted December 15, 2010 Share Posted December 15, 2010 if you do ini_set('post_max_size','10M'); or php_value post_max_size 20M in htaccess then run phpinfo() does it show the changes? ie. ini_set('post_max_size','10M'); phpinfo(); If you can't see the changes in phpinfo you may be at the mercy of your provider. I have had issues with ini_set not working but htaccess has always worked for me. Quote Link to comment Share on other sites More sharing options...
mme Posted December 15, 2010 Author Share Posted December 15, 2010 if you do ini_set('post_max_size','10M'); or php_value post_max_size 20M in htaccess then run phpinfo() does it show the changes? ie. ini_set('post_max_size','10M'); phpinfo(); If you can't see the changes in phpinfo you may be at the mercy of your provider. I have had issues with ini_set not working but htaccess has always worked for me. No, I tried with both however no changes are showing so it looks like I am going to look for a different host. Thanks for all your replies and help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.