I am working on my website and this website will require users to upload files; I have tried many ways to make this file uploaded to a folder and its location in database, I even cannot make the file stored in a folder in local host actually I am using "Dreamweaver 8"; this is the code I have used ...............please help:- ////////////the code <?php if($_POST['submit']){ include ("Ile Uploading.php"); $name = $_FILES['upload']['name']; $temp = $_FILES['upload']['temp_name']; $type= $_FILES['upload']['type']; $size = $_FILES['upload']['size']; if(($type=="image/jpeg") or ($type=="image/jpg") or ($type=="image/gif")){ if ($size<=100000){ move_uploaded_file($temp,$name); echo "<img src = '$name'>"; }else{ echo"The file:$name is too large...<br> The size is $size and needs to be less tan 100MB"; } }else{ echo "This type $type is not allowed"; } }else{ header("location: Ile Uploading.php"); } ?> //////////////end
you must put the full directory path (not url path) of the file destination to do it.. move_uploaded_file($temp,'c:/path/to/your/uploads/folder/'.$name); PHP:
There seems you did not specify any folder it should upload to. $dir = "./upload_dir" move_uploaded_file($temp,"{$dir}/{$name}"); PHP: Replace 'upload_dir' with your sub-folder name. Try and let me know results. regards
None of them works......I tried that:- ////////////the code <?php if($_POST['submit']){ include ("Ile Uploading.php"); $name = $_FILES['upload']['name']; $temp = $_FILES['upload']['temp_name']; $type= $_FILES['upload']['type']; $size = $_FILES['upload']['size']; if(($type=="image/jpeg") or ($type=="image/jpg") or ($type=="image/gif")){ if ($size<=100000){ ove _ uploaded _ file($temp,'c:/path/to/your/uploads/folder/'.$name);(does not work) echo "<img src = '$name'>"; }else{ echo"The file:$name is too large...<br> The size is $size and needs to be less tan 100MB"; } }else{ echo "This type $type is not allowed"; } }else{ header("location: Ile Uploading.php"); } ?> //////////////end as well as this :- ////////////the code <?php if($_POST['submit']){ include ("Ile Uploading.php"); $name = $_FILES['upload']['name']; $temp = $_FILES['upload']['temp_name']; $type= $_FILES['upload']['type']; $size = $_FILES['upload']['size']; if(($type=="image/jpeg") or ($type=="image/jpg") or ($type=="image/gif")){ if ($size<=100000){ $dir = "./upload_dir" ove_uploaded_file($temp,"{$dir}/{$name}");(there is an error here) echo "<img src = '$name'>"; }else{ echo"The file:$name is too large...<br> The size is $size and needs to be less tan 100MB"; } }else{ echo "This type $type is not allowed"; } }else{ header("location: Ile Uploading.php"); } ?> //////////////end
The folder is "READ ONLY" however, I tried to change the properties and it returns to "Read Only", should I try it through PHP code?
I have tried another codes from "W3school", and I don't know what I have to do:- "what is the mistakes?". The code is :- ///////////////////Beginning(this is the action php file of the form file) <?php if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; } if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; } } else { echo "Invalid file Properties"; } if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("C:\AppServ\www\Mysite\Images\Images/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "C:\AppServ\www\Mysite\Images\Images/" . $_FILES["file"]["name"]); echo "Stored in: " . "C:\AppServ\www\Mysite\Images\Images/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> ///////////last
I'm not reacting on your problem, your answer is found easily but i'm just want to point you to security problems. NEVER and i'll say again NEVER trust the 'filename' given by the user. Always use your OWN created filename and extension. Your example is very easy to abuse and hack your server!!!! b.t.w. move_file_uploaded doesn't need to specify a directory if you are using 'current' directory! Good luck and please check my comment and fix your security issue