PHP upload not working, maybe permission issues -


i need make upload page in site, i'm using altervista trial server. used tutorial http://www.w3schools.com/php/php_file_upload.asp upload doesn't work. maybe, read permission issue, don't have slightest idea on how change permissions of folders.

is possible add pdf in uploadable files?

thanks

uploadpage.html

<!doctype html> <html> <head> <meta charset="utf-8"> <title>documento senza titolo</title> <link href="valsilehome.css" rel="stylesheet" type="text/css"> </head>  <body>   <form action="/tmp/upload.php" method="post" enctype="multipart/form-data">     select image upload:     <input type="file" name="filetoupload" id="filetoupload">     <input type="submit" value="upload image" name="submit"> </form>  </body> </html> 

upload.php

<?php $target_dir = "/tmp/uploads";  $target_file = $target_dir . basename($_files["filetoupload"]["name"]); $uploadok = 1; $imagefiletype = pathinfo($target_file,pathinfo_extension); // check if image file actual image or fake image if(isset($_post["submit"])) {     $check = getimagesize($_files["filetoupload"]["tmp_name"]);     if($check !== false) {         echo "file image - " . $check["mime"] . ".";         $uploadok = 1;     } else {         echo "file not image.";         $uploadok = 0;     } } // check if file exists  if (file_exists($target_file)) {     echo "sorry, file exists.";     $uploadok = 0; } // check file size if ($_files["filetoupload"]["size"] > 500000) {     echo "sorry, file large.";     $uploadok = 0; }  // check if $uploadok set 0 error if ($uploadok == 0) {     echo "sorry, file not uploaded."; // if ok, try upload file } else {     if (move_uploaded_file($_files["filetoupload"]["tmp_name"], $target_file)) {         echo "the file ". basename( $_files["filetoupload"]["name"]). " has been uploaded.";     } else {         echo "sorry, there error uploading file.";     } } ?> 

as of w3 schools, have created many conditions example. don't need follow strictly. can use if needed.

here's minimal code can have

<!doctype html> <html> <body> <form action="" method="post" enctype="multipart/form-data">     select image upload:     <input type="file" name="filetoupload" id="filetoupload">     <input type="submit" value="upload image" name="submit"> </form> </body> </html> <?php if (isset($_post['submit']))  { echo 'succesfully uploaded'; $structure = 'uploadedfiles/'; $target_file = $structure.basename($_files["filetoupload"]["name"]); move_uploaded_file($_files["filetoupload"]["tmp_name"], $target_file); } ?> 

if use above code should create folder named uploadedfiles in folder keep file.

else if need create each folder each file upload should code.. create file's name folder each time.

<!doctype html> <html> <body> <form action="" method="post" enctype="multipart/form-data">     select image upload:     <input type="file" name="filetoupload" id="filetoupload">     <input type="submit" value="upload image" name="submit"> </form> </body> </html> <?php if (isset($_post['submit']))  { echo 'succesfully uploaded'; $structure = $_files["filetoupload"]["name"]; if (!mkdir($structure, 777, true))  {} $target_file = $structure.basename($_files["filetoupload"]["name"]); move_uploaded_file($_files["filetoupload"]["tmp_name"], $target_file); } ?> 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -