hye, im a beginner in php and i was told to create a dynamic online gallery. but, the problem is, i dont know how to create a “upload file” in php, although i have done a lot of research but, i just couldnt understand it.
i already tried this; http://www.w3schools.com/php/php_file_upload.asp however i didnt know how to connect from one file to another, i tried to use header(“location:…”) but, it didnt work, can anyone help me? thanks
Hi. Here is a very small file uploading script for you (all in one - html and php):
sample.php[php]<?php
$dest = ‘photos/’; // destination directory - where to upload file on server
$msg = ‘’;
if($_POST[‘but_upload’]){ // form submitted
if(is_uploaded_file($_FILES[“myfile”][“tmp_name”])){
if(copy($_FILES[“myfile”][“tmp_name”],$dest.$_FILES[“myfile”][“name”])){
$msg. = ‘File uploaded!’;
unlink($_FILES[“myfile”][“tmp_name”]); // delete temporary file from server
}
else{
$msg. = ‘Can not save file!
’;
}
}
else{
$msg. = ‘Choose a file to upload!
’;
}
}
?>
Upload File
<?php echo $msg ?> Choose a file:[/php] Note, in your application you will need to check uploading file type, maybe sanitize file name etc. Also, don't forget to set writting permission to directory where you will upload files using php script (in my example /photos)