mstabrey Posted May 11, 2006 Share Posted May 11, 2006 I'm looking for some code to be able to upload files to a server. Have found something on this site, but it's way to in-depth for what I need. All I'm looking for is a single field for the file name with a browse button, and then an upload button. Nothing more than this ie. no validation etc.Does something simple like this exist?TIAMart Link to comment https://forums.phpfreaks.com/topic/9531-file-upload/ Share on other sites More sharing options...
.josh Posted May 11, 2006 Share Posted May 11, 2006 [code]<?php if (!$file) { $form = "select a file to upload, biatch!<br>"; $form.="<form action='$PHP_SELF' method='post' enctype='multipart/form-data'>"; $form.=" <input type='file' name='file' size='50'><br>"; $form.=" <input type='submit' value='upload file!'>"; $form.="</form>"; } elseif ($file_name !=" ") { copy ("$file","$file_name") or die("could not upload your shit, man"); $form ="File upload succeeded...<br>"; $form.="<ul><li>sent: ".$file_name; $form.="<li>size: ".$file_size; $form.="<li>type: ".$file_type; } else { $form = "unknown error."; } echo $form;?>[/code] Link to comment https://forums.phpfreaks.com/topic/9531-file-upload/#findComment-35204 Share on other sites More sharing options...
mstabrey Posted May 11, 2006 Author Share Posted May 11, 2006 Wow thanks!2 things:1. Where do I specify a folder called "trailers" to upload to?2. I get an error message "Warning: copy(asoutput.log): failed to open stream: Permission denied in /usr/www/users/muizenj/test.php on line 17" when I press the upload button. Is this related to my question 1 possibly.Mart Link to comment https://forums.phpfreaks.com/topic/9531-file-upload/#findComment-35245 Share on other sites More sharing options...
Carth Posted May 12, 2006 Share Posted May 12, 2006 The upload form uploads the file to a temporary directory, which is why [a href=\"http://www.php.net/copy\" target=\"_blank\"]copy()[/a] is used to transfer it to where you want it. The second parameter is where to copy to. Make sure this location exists, and is writeable.If register_global isn't on, you can't use the $file or $file_name variable. You should use $_FILES['file']['tmp_name'] and $_FILES['file']['name'] etc..[code]<?php $location = "/path/to/trailers"; if (!$_FILES['file']['tmp_name']) { $form = "select a file to upload, biatch!<br>"; $form.="<form action='$PHP_SELF' method='post' enctype='multipart/form-data'>"; $form.=" <input type='file' name='file' size='50'><br>"; $form.=" <input type='submit' value='upload file!'>"; $form.="</form>"; } elseif($_FILES['file']['tmp_name'] != "none") { copy ($_FILES['file']['tmp_name'], $location.$_FILES['file']['name']) or die("could not upload your shit, man"); $form ="File upload succeeded...<br>"; $form.="<ul><li>sent: ".$_FILES['file']['name']; $form.="<li>size: ".$_FILES['file']['size']; $form.="<li>type: ".$_FILES['file']['type']; } else { $form = "upload failed"; } echo $form;?>[/code]Edit: mistakes Link to comment https://forums.phpfreaks.com/topic/9531-file-upload/#findComment-35272 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.