Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Upload Form Help

Upload Form Help

Upload Form Help

i have the Following form and php code i have three Folders STORAGE1 STORAGE2 STORAGE3 in my Script directory, when i try to upload a File it Constantly puts it into the Root Folder Ignoring everything, below is what i have so far , anyone could help me see the error please let me know if i select STORAGE1 the File Should be uploaded to the STORAGE1 Folder etc "needing path in mysql to come soon"

#---------START-PHP FORM-----("uploadform.php")---------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona...">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/JavaScript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
if (restore) selObj.selectedIndex=0;

<FORM ACTION="nextpage.php" METHOD="POST" ENCTYPE="multipart/form-data">
<P>Please browse and double-click the file to upload. Your filename must have one of the following extensions: .doc, .pdf, .ppt, .pps, .xls, .csv, .rtf, .txt, .htm, .html, .jpg, .gif, .png</p>
<P>File name: <br><INPUT class="inputform" TYPE="file" name="userfile" style="width:250px;"></p>
<select name="location" onchange="">
<option name="STORAGE1" value="STORAGE1/">STORAGE1</option>
<option name="STORAGE2" value="STORAGE2/">STORAGE2</option>
<option name="STORAGE3" value="STORAGE3/">STORAGE3</option>
<P><INPUT class="inputform" TYPE="submit" VALUE="Upload File"></p>

<INPUT class="inputform" TYPE=hidden name="MAX_FILE_SIZE" value="513024">
<INPUT class="inputform" TYPE=hidden name="users_ID" value="<?print($users_ID);?>">

#---------START-PHP UPLOAD-----("nexpage.php")---------------------------


//set non-executable file extensions you'll accept as an upload
$okext = array(".doc", ".pdf", ".ppt", ".pps", ".xls", ".csv", ".rtf", ".txt", ".htm", ".html", ".jpg", ".gif", ".png");

//check for oversize files or empty uploads
$thesize = $_FILES['userfile']['size'];

if ( ($thesize > 3513024) || ($thesize == 0) ){
<TITLE>File Upload 2</TITLE>
<body style="background:#CCCCFF">
<p align=center>Error... No file, or file too large.<br>
If your file is too large, please post it somewhere on your company\'s website, then use a URL link to it instead.</p>
<p align=center><a href="javascript:window.close();">Close Window</a></p>

//read the file from the temp location
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize($filename));

//set the path for your saving directory
// $respath = "PLC/"; //include trailing slash
$loc = $_POST["$location"];
//$respath = $loc; //include trailing slash
$respath = $loc;
echo '$loc';

//check for valid file extension
$resext = "";
$extarray = explode(".", $_FILES['userfile']['name']);

$extpos = count($extarray)-1;
$resext = ".".$extarray[$extpos];

if (!(in_array($resext, $okext))){
<LINK href="dladmin.css" type=text/css rel=stylesheet>
<TITLE>File Upload 2</TITLE>

<body style="background:#FFFFFF">
<p align=center>Error... Invalid filename extension.<br>
Your filename must have one of the following extensions: .doc, .pdf, .ppt, .pps, .xls, .csv, .rtf, .txt, .htm, .html, .jpg, .gif, .png</p>
<p align=center><a href="javascript:window.close();">Close Window</a></p>

//you can rename the file here if needed
$resname = $respath.$_FILES['userfile']['name'];

$resw = fopen($resname, "w");
fwrite($resw, $contents);

////// Don't forget to insert $resname into the db too! /////


RE: Upload Form Help

1. Have you checked what is actually getting set to your $loc variable? since that seems to be the basis for your $respath, are you sure that it is a valid path?

2. PHP has a function to move uploaded file to a specific directory. http://php.net/manual/en/function.move-uploaded-fi...


move_uploaded_file ( string $filename , string $destination ) 

Phil AKA Vacunita
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close