Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script upload problems

Status
Not open for further replies.

xWastedMindx

Technical User
Sep 3, 2002
67
US
Running Windows 2000 and IIS 5, with PHP 4.3.2

I'm trying to use a script for file uploading, and everything works fine up to the clicking of the upload button.

It seems to upload, but when I check the directory, nothing is there. I may have the absolute directory wrong..but I'm not sure.
I know I have all the file and directory permissions correct.

If someone can test this for me, it would be appreciated.
AIM name to contact me (help me): x Wasted Mind x

config.php
<?
//Advanced Uploader V1.00b
//Copyright 2002 ZachWhite.com
//By using this program you agree with the license provide with it.
//Script by Zach White zachwhite@zachwhite.com

$absolute_path = &quot; //Absolute path to where files are uploaded
$size_limit = &quot;yes&quot;; //do you want a size limit yes or no.
$limit_size = &quot;50000&quot;; //How big do you want size limit to be in bytes
$limit_ext = &quot;yes&quot;; //do you want to limit the extensions of files uploaded
$ext_count = &quot;4&quot;; //total number of extensions in array below
$extensions = array(&quot;.gif&quot;, &quot;.jpg&quot;, &quot;.jpeg&quot;, &quot;.png&quot;); //List extensions you want files uploaded to be
?>





[upload.php]

<?
//Advanced Uploader V1.00b
//Copyright 2002 ZachWhite.com
//By using this program you agree with the license provide with it.
//Script by Zach White zachwhite@zachwhite.com
if(!isset($upload)) {
$upload = &quot;&quot;;
}
switch($upload) {
default:
include &quot;config.php&quot;;
echo &quot;
<html>

<head>
<title>Upload</title>
</head>

<body topmargin=\&quot;10\&quot; leftmargin=\&quot;0\&quot; bgcolor=\&quot;#18576F\&quot; link=\&quot;#818EA0\&quot; vlink=\&quot;#5C697A\&quot; alink=\&quot;#818EA0\&quot; text=\&quot;#FFFFFF\&quot; style=\&quot;font-family: Verdana; font-size: 8pt; color: #FFFFFF\&quot;>



<div align=\&quot;center\&quot;>
<center>
<table border=\&quot;0\&quot; cellpadding=\&quot;0\&quot; cellspacing=\&quot;0\&quot; style=\&quot;border-collapse: collapse\&quot; bordercolor=\&quot;#111111\&quot; width=\&quot;400\&quot; id=\&quot;AutoNumber1\&quot;>
<tr>
<td bgcolor=\&quot;#5E6A7B\&quot; height=\&quot;25\&quot;>
<p align=\&quot;center\&quot;><font size=\&quot;2\&quot;><b>Upload File</b></font></td>
</tr>
<tr>
<td bgcolor=\&quot;#818EA0\&quot;><font size=\&quot;2\&quot;>The following restrictions apply:</font><ul type=\&quot;square\&quot;>
<li><font size=\&quot;2\&quot;>File extension must be <b>&quot;;
if (($extensions == &quot;&quot;) or ($extensions == &quot; &quot;) or ($ext_count == &quot;0&quot;) or ($ext_count == &quot;&quot;) or ($limit_ext != &quot;yes&quot;) or ($limit_ext == &quot;&quot;)) {
echo &quot;any extension&quot;;
} else {
$ext_count2 = $ext_count+1;
for($counter=0; $counter<$ext_count; $counter++) {
echo &quot;  $extensions[$counter]&quot;;
}
}
if (($limit_size == &quot;&quot;) or ($size_limit != &quot;yes&quot;)) {
$limit_size = &quot;any size&quot;;
} else {
$limit_size .= &quot; bytes&quot;;
}
echo&quot;</b></font></li>
<li><font size=\&quot;2\&quot;>Maximum file size is $limit_size</font></li>
<li><font size=\&quot;2\&quot;>No spaces in the filename</font></li>
<li><font size=\&quot;2\&quot;>Filename cannot contain illegal characters
(/,*,\,etc)</font><BR>
</li>
</ul>
<form method=\&quot;POST\&quot; action=\&quot;upload.php?upload=doupload\&quot; enctype=\&quot;multipart/form-data\&quot;>
<p align=\&quot;center\&quot;>
<input type=file name=file size=30 style=\&quot;font-family: v; font-size: 10pt; color: #5E6A7B; border: 1px solid #5E6A7B; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1\&quot;><br>
<br>
<button name=\&quot;submit\&quot; type=\&quot;submit\&quot; style=\&quot;font-family: v; font-size: 10pt; color: #5E6A7B; border: 1px solid #5E6A7B; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1\&quot;>Upload</button>
</p>
</form>
<p>
</td>
</tr>
<tr>
<td bgcolor=\&quot;#5E6A7B\&quot; height=\&quot;25\&quot;>
<p align=\&quot;center\&quot;><font size=\&quot;1\&quot;>
<a href=\&quot; color=\&quot;#FFFFFF\&quot;>
ZachWhite.com File Uploader</font></a></font><br>
<font size=\&quot;1\&quot;>Template By <a href=\&quot; <font color=\&quot;#FFFFFF\&quot;>Jan Ole Peek</font></a></font></td>
</tr>
</table>
</center>
</div>


</body>

</html>&quot;;
break;
case &quot;doupload&quot;:
include &quot;config.php&quot;;
$endresult = &quot;<font size=\&quot;2\&quot;>File Was Uploaded</font>&quot;;
if ($file_name == &quot;&quot;) {
$endresult = &quot;<font size=\&quot;2\&quot;>No file selected</font>&quot;;
}else{
if(file_exists(&quot;$absolute_path/$file_name&quot;)) {
$endresult = &quot;<font size=\&quot;2\&quot;>File Already Existed</font>&quot;;
} else {
if (($size_limit == &quot;yes&quot;) && ($limit_size < $file_size)) {
$endresult = &quot;<font size=\&quot;2\&quot;>File was to big</font>&quot;;
} else {
$ext = strrchr($file_name,'.');
if (($limit_ext == &quot;yes&quot;) && (!in_array($ext,$extensions))) {
$endresult = &quot;<font size=\&quot;2\&quot;>File is wrong type</font>&quot;;
}else{
@copy($file, &quot;$absolute_path/$file_name&quot;) or $endresult = &quot;<font size=\&quot;2\&quot;>Couldn't Copy File To Server</font>&quot;;
}
}
}
}
echo &quot;
<html>

<head>
<title>Upload</title>
</head>

<body topmargin=\&quot;10\&quot; leftmargin=\&quot;0\&quot; bgcolor=\&quot;#18576F\&quot; link=\&quot;#818EA0\&quot; vlink=\&quot;#5C697A\&quot; alink=\&quot;#818EA0\&quot; text=\&quot;#FFFFFF\&quot; style=\&quot;font-family: Verdana; font-size: 8pt; color: #FFFFFF\&quot;>



<div align=\&quot;center\&quot;>
<center>
<table border=\&quot;0\&quot; cellpadding=\&quot;0\&quot; cellspacing=\&quot;0\&quot; style=\&quot;border-collapse: collapse\&quot; bordercolor=\&quot;#111111\&quot; width=\&quot;400\&quot; id=\&quot;AutoNumber1\&quot;>
<tr>
<td bgcolor=\&quot;#5E6A7B\&quot; height=\&quot;25\&quot;>
<p align=\&quot;center\&quot;><font size=\&quot;2\&quot;><b>Upload File</b></font></td>
</tr>
<tr>
<td bgcolor=\&quot;#818EA0\&quot;>
<center> $endresult </center>
</td>
</tr>
<tr>
<td bgcolor=\&quot;#5E6A7B\&quot; height=\&quot;25\&quot;>
<p align=\&quot;center\&quot;><font size=\&quot;1\&quot;>
<a href=\&quot; color=\&quot;#FFFFFF\&quot;>
ZachWhite.com File Uploader</font></a></font><br>
<font size=\&quot;1\&quot;>Template By <a href=\&quot; <font color=\&quot;#FFFFFF\&quot;>Jan Ole Peek</font></a></font></td>
</tr>
</table>
</center>
</div>


</body>

</html>&quot;;
break;
}
?>
 
I strongly suggest you take a look at the PHP online manual in the section title &quot;Handling File Uploads&quot; (
PHP will save the file in the system's temp directory and set an array with the information that will tell you where to find the file. Perform a print_r() on $file -- it should be an array.

I also strongly recommend against using the &quot;@&quot; error-squelching operator during development. It may be producing an error that will help you figure out what is going on.

Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top