============END OF Index.html============
Below is the php script
==== control.php============
<?php
// Pick a file extension
if (preg_match('/^image\/p?jpeg$/i', $_FILES['upload']['type']))
{
$ext = '.jpg';
}
else if (preg_match('/^image\/gif$/i', $_FILES['upload']['type']))
{
$ext = '.gif';
}
else if (preg_match('/^image\/(x-)?png$/i',
$_FILES['upload']['type']))
{
$ext = '.png';
}
else
{
$ext = '.unknown';
}
// The complete path/filename
$filename = 'C:/xampp/htdocs/Php_Msql/fileUp/uploads/' . time() . $_SERVER['REMOTE_ADDR'] . $ext;
// Copy the file (if it is deemed safe)
if (!is_uploaded_file($_FILES['upload']['tmp_name']) or
!copy($_FILES['upload']['tmp_name'], $filename))
{
$error = "Could not save file as $filename!";
include $_SERVER['DOCUMENT_ROOT'] . '/Php_Msql/fileUp/includes/error.html.php';
exit();
}
===============END OF Control.php==================
The error message i get for trying different files is below
==>Error<==: Could not save file as C:/xampp/htdocs/Php_Msql/fileUp/uploads/1449047923::1.unknown!
It can not save it as the extension is set as unknown; you also have :: in the file path that may be a problem.
I assume your extension test is failing and the preg_match seems a bit over complicated to me. I would simplfy the extension check first and get it working and then add the preg_match if you want it.
You are aslo saving to a computer path where I would use a relative path so again try something simple like saving to the same folder first and see what happens. I use xampp and never need to use $filename = āC:/xampp/htdocs/Php_Msql/fileUp/uploads/ā I would just have something like $filename = ā/fileUp/uploads/ā
I always recommend taking little steps and get each to work before going onto the next rather than go for the whole code in one go. You can also add some echoās at various parts within the code to confirm the variable contains what you expect.
Thank you Rubble for your time i appreciate.
You are right the preg_match() is failing, but even when i try to hard code the variable ($ext = .jpg) and try uploading a a JPEG file it still gives same error.
the additional character ** :: ** is from the function ($_SERVER[āREMOTE_ADDRā]) which actually returns ::1
thank you again for your time as i await your assistance
This is the IPV6 equivalent of localhost, or 127.0.0.1. The issue is youāre not validating what comes back as that address, so you need a short function to strip out characters you canāt use as part of a filename. Iām not even sure Iād like to leave the full-stop characters in if it came back as an IPV4 address.
I donāt really understand preg_match() at all, but are you checking for a file to be uploaded with the ā.jpgā extension? I can see you check for jpeg, gif and png, would the first check also match for jpg?