jej1216 Posted November 13, 2007 Share Posted November 13, 2007 I found this old post : http://www.phpfreaks.com/forums/index.php/topic,93267.0.html which has most of the answers to what I want to do. I need to have a user upload files to a location on the server. Here is my code (thanks to the link above!): <?php $location = "/forms"; if (!$_FILES['file']['tmp_name']) { $form = "select a file to upload<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 file."); $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; ?> When the page loads, I get these messages: Notice: Undefined index: file in /usr/local/php_classes/forms/ehi_forms_upload.php on line 11 Notice: Undefined variable: PHP_SELF in /usr/local/php_classes/forms/ehi_forms_upload.php on line 13 select a file to upload When I try to upload a file, I get this error: Warning: copy(/formsphonelist.log): failed to open stream: Permission denied in /usr/local/php_classes/forms/ehi_forms_upload.php on line 18 could not upload file. I know this is close to what I need --- but what does this error mean? TIA, jej1216 Quote Link to comment Share on other sites More sharing options...
jpratt Posted November 13, 2007 Share Posted November 13, 2007 Check your permissions on your folder and your php.ini file to make sure you have file uploads on. Quote Link to comment Share on other sites More sharing options...
jej1216 Posted November 14, 2007 Author Share Posted November 14, 2007 Thanks - we use Joomla, and register_globals needs to be turned off for Joomla to work. /$PHP_SELF can not be used because it will not work without register_globals being enabled. I changed the code to this: <?php $location = "/usr/local/php_classes/forms/"; if (!$_FILES['file']['tmp_name']) { $form = "select a file to upload<br>"; $form.="<form 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 file."); $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; ?> I also had to chmod 777 the folder I was uploading to. I still have the "Notice: Undefined index: file in /usr/local/php_classes/forms/ehi_forms_upload.php on line 11" issue, but I think that is an undefined variable in the line if (!$_FILES['file']['tmp_name']) { Thanks, jej1216 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.