Viewed   72 times

I've been slowly learning PHP and have found an array of information on the subject and solutions posted by other developers. I am attempting to have an android application upload a file to PHP server via HTTP post. However something is not working on my server side wile attempting to write to file in PHP.

Here is the PHP code:

// Where the file is going to be placed
$target_path = "/var/www/media2net/uploads/uploads";

/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);

if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']) .
        " has been uploaded";
    chmod("uploads/" . basename($_FILES['uploadedfile']['name']), 755);
} else {
    echo "There was an error uploading the file, please try again!";
    echo "filename: " . basename( $_FILES['uploadedfile']['name']);
    echo " target_path: " .$target_path;

I already know from inspecting wire shark on client side that http post is sent out correctly, also I have ensured that the directory I'm writing the file to has the correct permissions, and php safe mode is set to off.

the output from apache2 error.log file reads

[Wed Dec 05 09:25:36 2012] [error] [client] PHP Warning:  
move_uploaded_file(): Unable to move '/tmp/phpVLOnn3' to  
in /var/www/media2net/upload.php on line 9

Any help with this problem or further ways to trouble shoot this would be appreciated.



Change upload permissions for /var/www/media2net/uploads/ either by changing owner with "chown" or by "chmod"


$ sudo chown apache:apache /var/www/media2net/uploads/
$ sudo chmod 755 /var/www/media2net/uploads/

Also, if downloaded_file.png already exists in that directory and it's owned by another user, then you would need to change ownership on that file as well.

$ sudo chown apache:apache /var/www/media2net/uploads/downloaded_file.png

This way, it can be successfully overwritten by Apache.

Sunday, November 13, 2022

Well here's one sample code, but you should read and try on your own before asking:

$connection = ftp_connect($server);

$login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);

if (!$connection || !$login) { die('Connection attempt failed!'); }

$upload = ftp_put($connection, $dest, $source, $mode);

if (!$upload) { echo 'FTP upload failed!'; }


Hope it helps you getting started

Monday, September 26, 2022

I suspect the root cause of your problem may be this line from the manual:

As of PHP 5.2.0, value must be an array if files are passed to this option with the @ prefix.

In any case, try this code and if it doesn't work, let me know what error message(s) you get so I can debug:

$uploadPath = rtrim(dirname(__FILE__),'/').'/images/wallimages/'.random_pic();
if (!is_file($uploadPath)) die("The file '$uploadPath' does not exist");
if (!is_readable($uploadPath)) die("The file '$uploadPath' is not readable");

$postFields = array (
  'nameOfFileControl' => "@$uploadPath",
  'someOtherFormControl' => 'some value'
  // Adjust this array to match your post fields.
  // Ensure you keep the array in this format!

$ch = curl_init(''.$url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);

$result = curl_exec($ch);

    return 'Curl error: ' . curl_error($ch);
curl_close ($ch);
return $result;
Monday, December 26, 2022

The query is failing - you need to wrap quotes around strings in MySQL:

$strSQL = "SELECT * FROM gu_service_cat WHERE id = '" . $_GET["serviceName"] . "'";

plus, the $rs should be BELOW the $strSQL...

Sunday, October 9, 2022

Process limit

"Is there a process limit I should look into"

It's suspected somebody (system admin?) set limitation of max user process. Could you try this?

$ ulimit -a
max user processes              (-u) 16384

Run preceding command in PHP. Something like :

echo system("ulimit -a");

I searched whether php.ini or httpd.conf has this limit, but I couldn't find it.

Error Handling

"even a better way to handle these processes as to get around the error all together?"

The third parameter of exec() returns exit code of $cmd. 0 for success, non zero for error code. Refer to .

exec($cmd, &$output, &$ret_val);

if ($ret_val != 0)
    // do stuff here
    echo "successn";
Sunday, November 6, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :