I'm making a form for admins on my site to submit new videos. the form page has several text boxes (for info like name of video, description, ect.) and a few file upload boxes (for flv video format, mp4 format, ect.)

But when it passes to the next page, when phgp tries to pick up the $_POST data from the form, it's all comming up empty. Take a look:

HTML form:

<form name="vid_form" method="post" enctype="multipart/form-data" action=""><br>
Video title: <input type="text" size="20" maxlength="25" name="form_title"><br>
Description: <TEXTAREA name="form_desc" cols=30 rows=4 maxlength="190"></TEXTAREA><br>
Target path:  <input type="text" size="15" maxlength="15" name="form_target"> (Expample "desired_dictionary/")<br>
Flv file: <input name="flv_file" type="file" /><br><br>
Mp4 file: <input name="mp4_file" type="file" /><br><br>
Jpg screenshot: <input name="jpg_file" type="file" /><br><br>
<input type="submit" value="Upload Video!" />

PHP code:

$form_title = $_POST['form_title'];
$form_desc = $_POST['form_desc'];
$target_path = $_POST['form_target'];

//upload flv file
$target_path = $target_path . basename( $_FILES['flv_file']['name']); 

if(move_uploaded_file($_FILES['flv_file']['tmp_name'], $target_path)) {
    $err_check[1] = "SUCCESS";
} else{ $err_check[1] = "FAILED";  }


//upload mp4 file
$target_path2 = $target_path2 . basename( $_FILES['mp4_file']['name']); 

if(move_uploaded_file($_FILES['mp4_file']['tmp_name'], $target_path2)) {
    $err_check[2] = "SUCCESS";
} else{ $err_check[2] = "FAILED";  }

//upload jpg screenshot
$target_path3 = $target_path3 . basename( $_FILES['jpg_file']['name']); 

if(move_uploaded_file($_FILES['jpg_file']['tmp_name'], $target_path3)) {
    $err_check[3] = "SUCCESS";
} else{ $err_check[3] = "FAILED";  }

Does anyone have any ideas for why it's not passing the data? Thanks! I've been battling with this all afternoon.

Dani AI

Generated

Two quick fixes will unblock this. First, keep the form as POST with enctype="multipart/form-data". GET cannot carry file content, and uploaded files never arrive in $_GET/$_REQUEST anyway; the binary data comes only in $_FILES and text fields in $_POST. That is the required setup for file uploads. (developer.mozilla.org)

Second, your original “empty $_POST” symptom usually means the request exceeded post_max_size. When that happens, PHP discards the body and both $_POST and $_FILES are empty. With FLV/MP4 this is common. Set, at minimum, these ini values (and restart PHP/Apache as needed): upload_max_filesize (per-file), post_max_size (entire request, must be larger than upload_max_filesize), and ensure file_uploads=On. Also confirm the temp and destination directories are writable. (php.net)

Drop this at the very top of vid_manager.php to see exactly what the server receives and why a move fails:

ini_set('display_errors', 1);
error_reporting(E_ALL);

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    exit('This endpoint expects POST.');
}

var_dump($_POST, $_FILES); // confirm fields and upload errors

$base = __DIR__ . '/uploads'; // your writable target dir
if (isset($_FILES['flv_file']) && $_FILES['flv_file']['error'] === UPLOAD_ERR_OK) {
    $name = basename($_FILES['flv_file']['name']);
    $to = rtrim($base, '/\\') . DIRECTORY_SEPARATOR . $name;
    if (!is_dir($base) || !is_writable($base)) { exit('Upload dir not writable.'); }
    if (!move_uploaded_file($_FILES['flv_file']['tmp_name'], $to)) { exit('move_uploaded_file failed.'); }
}

Notes:

  • Follow @Zagga’s advice to echo/inspect values; it makes the problem obvious.
  • Using $_GET as suggested by will pass text fields but never the files.
  • If nothing shows up in $_FILES, check your error log for a “POST Content-Length exceeds limit” message and then raise the limits described above. Also verify you call move_uploaded_file on the tmp_name and that the destination exists. (php.net)

Recommended Answers

All 4 Replies

use $_GET OR $_REQUEST in place of $_POST . because you submit form to another page.

Member Avatar for Member #671080

Hi mybluehair,

your form values are being POSTed to vid_manager.php ok, as you can see if you place some echo statements on line 4.
What error are you getting?


Zagga

Check for other forms on page. The chances could be that previous forms are not closed properly

Ok, so I tried what raju said, and used $_GET and that seems to be carrying info over to vid_manager.php just fine, but the problem now is that the files arn't being processed. Here is the top of my new form:

<form name="vid_form" method="get" enctype="multipart/form-data" action=""><br>

And here is the code in vid_manager.php that tries to retrieve the files that were uploaded:

$target_path = $_GET['form_target'];
$target_path2 = $_GET['form_target'];
$target_path3 = $_GET['form_target'];

//upload flv file
$target_path = $target_path . basename( $_FILES['flv_file']['name']); 

if(move_uploaded_file($_FILES['flv_file']['tmp_name'], $target_path)) {
    $err_check[1] = "SUCCESS";
} else{ $err_check[1] = "FAILED";  }


//upload mp4 file
$target_path2 = $target_path2 . basename( $_FILES['mp4_file']['name']); 

if(move_uploaded_file($_FILES['mp4_file']['tmp_name'], $target_path2)) {
    $err_check[2] = "SUCCESS";
} else{ $err_check[2] = "FAILED";  }

//upload jpg screenshot
$target_path3 = $target_path3 . basename( $_FILES['jpg_file']['name']); 

if(move_uploaded_file($_FILES['jpg_file']['tmp_name'], $target_path3)) {
    $err_check[3] = "SUCCESS";
} else{ $err_check[3] = "FAILED";  }

Now, all of my $err_checks are comming up "failed". Im not sure whats wrong. Any ideas?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.