php fopen dynamic file path -


i trying make simple script allow user upload image database. have problem php fopen function.

i need allow user upload image file on computer path file different every time.

<form method="post">         <input type="file" name="img">         <input type="submit" value="uload">     </form> 

this simple form returning string value of file , need open file using fopen function needs direct path file.

fopen($_post["img"],"r"); 

this works if file in same directory php script.

so asking if there way how find file stored open using fopen function.

i advice first have php manual file uploads: http://www.php.net/manual/en/features.file-upload.post-method.php

because such code may open security hall in system. speaking not recommended directly execute users files before doing check virus scan, binary signature of images, image validaty trying resize it, etc.. performance perspective not recommended save them in database. in addition if choose upload directory permission should set proper.

i copy here sample file upload code modified case php manual:

html part:

<!-- data encoding type, enctype, must specified below --> <form enctype="multipart/form-data" action="your_upload_file.php" method="post">     <!-- name of input element determines name in $_files array -->     <input name="img" type="file" />     <input type="submit" value="send file" /> </form> 

php part:

<?php $uploaddir = '/var/www/uploads/'; $uploadfile = $uploaddir . basename($_files['img']['name']);  //at point may check: /* 1. upload errors in $_files 2. virus check. 3. binary check images type 4. size check image 5. actual image resize confirm valid image. */  //after safe, move temporary file permanent store. echo '<pre>'; if (move_uploaded_file($_files['img']['tmp_name'], $uploadfile)) {     echo "file valid, , uploaded.\n"; } else {     echo "possible file upload attack!\n"; }  echo 'here more debugging info:'; print_r($_files);  print "</pre>";  ?> 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -