Hi,
I just recently migrate from a WAMP server to a ubuntu server.
I was doing a simple file uploading with simple parameter.
This is my code working on a WAMP Server
echo"<form action='' method=POST enctype=multipart/form-data>";
//method post to make it invisible
echo"<input type=hidden name=MAX_FILE_SIZE value=100000>";
//echo"<input type=file name=uploadedfile onchange=this.form.submit()>";
echo"<input type=button value='File to Upload' class=choose1 id=pseudobutton>";
echo"<input type=file name=uploadedfile class=hide1 id=openssme>";
echo"<input type=hidden name=uploadedfile>";
echo"<input type=submit name=upload value=Upload class=upload>";
echo"</form>";
//START OF UPLOAD
//check if upload is selected
if (isset($_POST['upload'])) {
$ext = "";
//Check the availability of the file. empty evaluate to true if empty. check if it is the recent uploaded file. validate filename
echo "First Condition";
if ((!empty($_FILES["uploadedfile"])) && ($_FILES['uploadedfile']['error'] == 0) && (is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) && (preg_match("/^[A-Za-z0-9].*\.[a-z]{0,3}$/", $_FILES['uploadedfile']['tmp_name']))) {
//basename return component name. strtolower change to lowercase.
$filename = strtolower(basename($_FILES['uploadedfile']['name']));
//substr return some string after dot
$ext = substr($filename, strrpos($filename, '.') + 1);
echo"Second Condition";
//check if file extension is c and less than 100000kb
if (($ext == "c") && ($_FILES["uploadedfile"]["size"] < 100000) && ($_FILES["uploadedfile"]["type"] == "text/plain")) {
//add the dot
$ext = "." . $ext;
//file directory
$newname = dirname(__FILE__) . '/upload/' . $_FILES["uploadedfile"]["name"];
echo $newname;
//move_uploaded_file is php function for directory
if ((move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $newname))) {
print('<br><br><br><br><br><table>');
print('<tr><td width=100px>File Name</td><td width=100px>File Size</td><td width=100px>Last Modified</td></tr>');
print('<tr><td><a href="$newname">'.$_FILES['uploadedfile']['name'].'</a></td><td>' . round($_FILES['uploadedfile']['size'] / 1024, 4) . ' Kb</td><td>' . date("d F Y H:i:s.", filemtime($newname)) . '</td></tr>');
print('</table>');
} else {
print('error');
}
} else {
print('Error: Only .c files <500Kb');
}
} else {
$filename = NULL;
}
}
In the ubuntu server, the code above is not working. I need to modify
if ((!empty($_FILES["uploadedfile"])) && ($_FILES['uploadedfile']['error'] == 0) && (is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) && (preg_match("/^[A-Za-z0-9].*\.[a-z]{0,3}$/", $_FILES['uploadedfile']['tmp_name'])))
into
((!empty($_FILES["uploadedfile"])) && ($_FILES['uploadedfile']['error'] == 0) && (is_uploaded_file($_FILES['uploadedfile']['tmp_name'])))
The if statement parameter
(preg_match("/^[A-Za-z0-9].*\.[a-z]{0,3}$/", $_FILES['uploadedfile']['tmp_name']))
is not executed.
Why is it giving a false statement?
Now I am stuck at
if ((move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $newname)))
At first I though it was some problem with the directory.
However the $newname provide me with
/var/www/upload/test1.c which I believe is correct.
why does the move_uploaded_file not working?
The output message that I am currently receiving
first conditionsecond condition/var/www/upload/test1.cerror
How can I fix this problem? Is it permission issue perhaps?
Thanks in advance