Hello. I have a php file with a form on it. the form has a few text fields and a few file fields. The problem is that for some weird reason the file upload fields screw everything up.

After I press submit, it carries NO data to the fallowing page. But when I troubleshot, I took out the file fields, and everything worked fine. (Except only I cant upload files)

Here is the form...

video_adder.php

<form name="vid_form" method="post" enctype="multipart/form-data" action="$PHP_SELF"><br>
	<input type="hidden" name="admin_action" value="submit_new">
        Video title: <input type="text" size="20" maxlength="25" name="form_title"><br /><br>
	Description: <TEXTAREA name="form_desc" cols=30 rows=4 maxlength="190"></TEXTAREA><br><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!" />

Then here is the script that retrieves the data (note that we check if "admin_action" has a value)

video_adder.php

$admin_action = $_POST['admin_action'];


if($admin_action != NULL){
$form_title = $_POST['form_title'];
$form_desc = $_POST['form_desc'];

$target_path = $_POST['form_target'];
$target_path2 = $_POST['form_target'];
$target_path3 = $_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";  }


//put in mysql data

$result = mysql_query("INSERT INTO  `videos` (`name`,`description`)VALUES ('$form_title',  '$form_desc')");

}

So when I run this code, fill in the form, and click upload, $admin_action is coming up NULL which means none of the form data is getting passed. But again, when I troubleshoot and take out the upload fields, $admin_action and all the other form data passes through just fine.

So any ideas? I've been working on this for days. Thanks!

Recommended Answers

All 9 Replies

Have you tried like this....

<form name="vid_form" method="post" enctype="multipart/form-data" action="<?php echo $PHP_SELF;?>">

code all yor html in small alphabets if using xhtml

try givig full path names to the files to be uploaded

@syamsasi, yes, but all that html is in a echo statement, so no need to.

@zerocool21, The path names arnt the problem if even the $admin_action text field isn't passing threw

Here I have checked with your form and its worked ... May be post data is exceeding the limit ( due to file size and all ) ... have you tried with a small size file for a testing ? First try to upload an image only ...

html in echo needs to properly formatted using escape("\") and dot symbol before PHP statements ...

Here I have checked with your form and its worked ... May be post data is exceeding the limit ( due to file size and all ) ... have you tried with a small size file for a testing ? First try to upload an image only ...

Alright, I tried, and yes, that does seem to fix the problem of the data not passing to the next page. So now I have 2 problems left. If file size is the problem, I need to figure out a way to raise that file size limit. Secondly, I'm getting these errors after submitting the form:

Warning: move_uploaded_file(fdgg/remix.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in video_adder.php on line 169

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phprcIU8R' to 'fdgg/remix.jpg' in video_adder.php on line 169

Warning: move_uploaded_file(fdgg/remix.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in video_adder.php on line 177

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpWkS5lX' to 'fdgg/remix.jpg' in video_adder.php on line 177

Warning: move_uploaded_file(fdgg/remix.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in video_adder.php on line 184

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpvlHlH3' to 'fdgg/remix.jpg' in video_adder.php on line 184

Any Ideas for the problems? Thanks for the help so far :)

Maximum upload file size is specified in php.ini . upload_max_filesize is the name for storing that. By default I think it will be 2MB .. If you are using VPS you can edit that using your cpanel for VPS .. Otherwise php.ini file should edit for this ... according to this variable other settings like maximum memory and all should change ( for high input size )

And for this error ..
Check the folder is created in server....
have you spelled the path correctly ( and check forward slashes (/) in path )
Check the permission of the folder in server .. is it writable .. if not make it writable

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.