How might I go about such a task? :confused:
Printable View
How might I go about such a task? :confused:
the process is fairly simple, you need the HTML obviously:
when the file is uploaded, it will go into the temp directory on the server, all the php script has to do is move it to where you want it. Just use php's copy function to move it http://www.php.net/manual/en/function.copy.php , since if you don't move the temp file, it will get deleted when the script fnishes.Code:<form enc-type="multipart/form-data" action="upload.php" method="post"
<input type="hidden" name="MAX_FILE_SIZE" value="1000">
Upload: <input type="file" name="userfile">
<input type="submit" value="Upload File">
</form>
The value in $userfile is the location of the temp file
$userfile_name is the filename
$userfile_size is the size (bytes)
$userfile_type is the mime type
Nifty, I'll try it out tomorrow considering I don't want to screw up my host and I don't have PHP running because I just reformatted :D
Arrrrrrrg:
My code:Quote:
Uploading toptitle.gif (16578 bytes)...
Warning: Unable to create '/usr/home/m/r/mrskramercom/public_html/students/talabac/var/tmp/phpIewkV3': No such file or directory in /usr/home/m/r/mrskramercom/public_html/students/uploadfile.php on line 17
Failed to upload!
Why? WHY!? WHYYYYYYYYYYYYYY! BTW, I chmod'ed all directories to 777 and it's STILL doing this. http://www.mrskramer.com/students/uploadfile.phpQuote:
<html>
<head>
<title>MrsKramer.com > Upload File</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?
if (isset($userfile))
{
echo '<font face="Verdana, Arial, Helvetica, sans-serif" size="2">';
echo "Uploading $userfile_name ($userfile_size bytes)...";
if (!file_exists($studentname))
{
mkdir($studentname, 0777);
}
if (!copy($userfile, "/usr/home/m/r/mrskramercom/public_html/students/$studentname$userfile"))
{
echo '<b>Failed to upload!</b>';
}
else
{
echo '<b>Upload successful</b> (<a href="uploadfile.php">Upload another file</a>)';
}
echo '</body>';
echo '</html>';
exit;
}
?>
<FORM ENCTYPE="multipart/form-data" ACTION="uploadfile.php" METHOD="POST">
<table border="0" cellspacing="0" cellpadding="5">
<tr>
<td bgcolor="#EEEEEE"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Name:</b>
<? require('studentlistdropdown.php'); ?>
</font> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td bgcolor="#EEEEEE">
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>File
to upload:</b></font></p>
<ul>
<li><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Only
allowed types are GIF, JPG, JPEG, PNG, CLASS, HTM, and HTML)</font></li>
<li><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Maximum
file size is 10,000 bytes (about 10 KB)</font></li>
<li><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Files
that are not directly referenced (i.e., for storage only) may be deleted
as space on the server is limited)</font></li>
<li><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Accessing
http://www.mrskramer.com/<i>lastname</i>/ will open http://www.mrskramer.com/<i>lastname</i>/index.html.</font></li>
</ul>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="File" name="userfile" size="30" maxlength="255"></font></p>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td bgcolor="#EEEEEE">
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#FF0000">Warning!
Any existing file with the same name will be overwritten!</font><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><br>
Click the Upload button only once.</font></p>
<p>
<input type="submit" value="Upload">
</p>
</td>
</tr>
</table>
</form>
</body>
</html>
if (!copy($userfile, "/usr/home/m/r/mrskramercom/public_html/students/$studentname$userfile"))
should be
if (!copy($userfile, "/usr/home/m/r/mrskramercom/public_html/students/$studentname/$userfile"))
When I do that, I get two /s in a row.
just noticed,
why are you using 2 $userfile? try this
if (!copy($userfile, "/usr/home/m/r/mrskramercom/public_html/students/$studentname/$userfile_name"))
Cheers, it works :D
*** is 'chmod' ???
that sets the permissions to a file so you can read or write or execute. for all users, owners, and groups
777 is full access for all everybody
755 is where you want it be most of the time.
444 is read only.
thanx scoutt. where would i change these settings ?? i know something like that is accessable through some FTP browser i have though :D
it all depends on what ftp program you use. I use ws_ftppro and if I right click on a file on the server it gives me the choice of chmod. then it opens another window where I can check and uncheck boxes to get the desired result.
lol, sorry scoutt, i am @ home now and thats the same app i use (ws_ftp_pro) i'll check it out. thanx m8 :)