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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I tried to run the following code t

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194
I tried to run the following code to upload a image file to my server but always I get the following error: Couldn't Copy File To Server.
Thanks in advance for any help.

by the way, anbody can guide me to a simple php-ftp code to do that?

----------------------------------------
the config file:

<?


$absolute_path = &quot;/usr/local/apache/htdocs/myfolder&quot;; //Absolute path to where files are uploaded
$size_limit = &quot;no&quot;; //do you want a size limit yes or no.
$limit_size = &quot;20000000&quot;; //How big do you want size limit to be in bytes
$limit_ext = &quot;no&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
?>

-----------------------------------------
the upload file:

<?php


switch($upload) {
default:
include &quot;config.php&quot;;
echo &quot;
<html>

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

<body>



<div>
<center>
<table border=\&quot;0\&quot; id=\&quot;AutoNumber1\&quot;>
<tr>
<td>
<p><b>Upload File</b></font></td>
</tr>
<tr>
<td>The following restrictions apply:</font><ul>
<li>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;&nbsp; $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>Maximum file size is $limit_size</li>
<li>No spaces in the filename</li>
<li>Filename cannot contain illegal characters
(/,*,\,etc)<BR>
</li>
</ul>
<form method=\&quot;POST\&quot; action=\&quot;$PHP_SELF?upload=doupload\&quot; enctype=\&quot;multipart/form-data\&quot;>
<p align=\&quot;center\&quot;>
<input type=file name=file size=30><br>
<br>
<button name=\&quot;submit\&quot; type=\&quot;submit\&quot;>Upload</button>
</p>
</form>
<p>
</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>



<div align=\&quot;center\&quot;>
<center>
<table>
<tr>
<td>
<p align=\&quot;center\&quot;><b>Upload File</b></td>
</tr>
<tr>
<td>
<center> $endresult </center>
</td>
</tr>

</table>
</center>
</div>


</body>

</html>&quot;;
break;
}
?>
 
Remove that [insert expletive here] &quot;@&quot; symbol from in front of the copy function. It's supressing any error messages which the copy function is producing.

And I think at this juncture, it would be nice to know what the error message is.

______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top