Why wont this work? I want to upload the file with a new file name (Example: the user uploads a file called myfile.txt and my php code uploads it as u_$vartitle.txt) PHP Code: $uploadfileloc = '/uploads/u_' . $vartitle . '.txt'; $varpicurl = '/uploads/img/i_' . $vartitle . '.gif'; if (move_uploaded_file($_FILES['filename']['tmp_name'], $uploadfileloc) && move_uploaded_file($_FILES['imgfilename']['tmp_name'], $varpicurl)) { echo('success'); } else { echo('fail'); } Code (markup): Thanks.
you should check is empty,if empty will fail,and do you upload the two files the same time? <form name="form1" method="post" action="file.php" enctype="multipart/form-data"> <input type="file" name="file1"> <input type="file" name="file2"> <input type="submit" value="upload" > </form> print_r($_FILES); you should add these two judge condition empty($_FILES["file1"]) empty($_FILES["file2"]))
I checked using if(empty($_FILES['filename'])) { echo('error') } else { //code here } Code (markup): and they are not empty cause the code continued to execute. And yes I am using the correct form and encryption type. It can read the file when I put it through $_FILES['filename']['size'] validation, it just won't let me upload the files. Why? Is there a way I can get error information to tell me where I went wrong?
Yes. The directory is writable. What else could be the problem and is there anyway PHP could tell me where I went wrong like it normally does? Thanks.
$uploadfileloc = '/uploads/u_' . $vartitle . '.txt'; $varpicurl = '/uploads/img/i_' . $vartitle . '.gif'; if( (is_writable('/uploads')) && is_writable('/uploads/img')){ $savefile = move_uploaded_file($_FILES['filename']['tmp_name'], $uploadfileloc); $saveimage = move_uploaded_file($_FILES['imgfilename']['tmp_name'], $varpicurl); if ($savefile && $saveimage) { echo('success'); } else { echo('fail'); } }else{ echo 'Not Write able'; } PHP: You need to check tmp_name too.
I searched the internet somemore and found out that these PHP commands treat the document as the basename. With some extra code I was able to resolve the problem. Thanks everyone!
I have same problem few months ago, You should write your form tag like this : <form action="action.php" method="post" enctype="application/x-www-form-urlencoded" name="form0" id="form0"> HTML: enctype="application/x-www-form-urlencoded"
Following code worked for me , please create uploads/profile folders and give write permision HTML Form <form method="POST" action="mypage.php" id="thisform" enctype="multipart/form-data" > <input name="uploadedfile" type="file" /> </form> HTML: mypage.php $target_path = "uploads/profile/".$uid."/"; if(file_exists($target_path)==false ){ mkdir($target_path, 0775); } $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); //echo $target_path; if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { // echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; }else{ // echo "There was an error uploading the file, please try again!"; } PHP: