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!

Problem: Uploading Images

Status
Not open for further replies.

alsaffar

Programmer
Oct 25, 2001
165
KW
I found a nice php script to upload files, but every time I upload an image it gets correpted when it reaches the server, see my code:

Code:
<?php 
 
$maxsize = &quot;200000&quot;; 
$path = &quot;/path/to/the/upload/directory/&quot;; 
 
if($uploads <= 1) 
{ 
    $uploads = 5; 
} 
$fields = $uploads + $uploads; 
 
for($n = 0; $n < $uploads; $n++) 
{ 
    if($uploadedFile[$n] != &quot;&quot; && $uploadedFile[$n] != &quot;none&quot;) 
    { 
    copy(&quot;$uploadedFile[$n]&quot;, &quot;$path$uploadedFile_name[$n]&quot;); 
    rename(&quot;$path$uploadedFile_name[$n]&quot;, &quot;$path$fileName[$n]&quot;); 
    if(file_exists(&quot;$path$fileName[$n]&quot;)) 
    { 
        print(&quot;upload successful for $fileName[$n] - $uploadedFile_size[$n] bytes<br>\n&quot;); 
    } 
    else 
    { 
        print(&quot;error: upload failed<br>\n&quot;); 
    } 
    } 
} 
 
print(&quot;<form action=\&quot;$PHP_SELF\&quot; method=\&quot;POST\&quot; enctype=\&quot;multipart/form-data\&quot;>\n&quot;); 
print(&quot;<input type=\&quot;hidden\&quot; name=\&quot;MAX_FILE_SIZE\&quot; value=\&quot;$maxsize\&quot;>\n&quot;); 
print(&quot;<table border=\&quot;0\&quot; cellpadding=\&quot;0\&quot; cellspacing=\&quot;3\&quot;><tr><td>\n&quot;); 
print(&quot;<b>Name:</b></td><td>\n&quot;); 
print(&quot;<b>File Location:</b></td></tr>\n&quot;); 
 
for($i = 1; $i <= $uploads; $i++) 
{ 
    print(&quot;<tr><td><input type=\&quot;text\&quot; name=\&quot;fileName[]\&quot; size=\&quot;13\&quot;></td><td>\n&quot;); 
    print(&quot;<input type=\&quot;file\&quot; name=\&quot;uploadedFile[]\&quot; size=\&quot;25\&quot;></td></tr>\n&quot;); 
} 
 
print(&quot;<tr><td align=\&quot;center\&quot;><input type=\&quot;submit\&quot; value=\&quot;UPLOAD\&quot;></td><td>\n&quot;); 
print(&quot;<a href=\&quot;$PHP_SELF?uploads=$fields\&quot;>More Upload Fields</a></td></tr>&quot;); 
print(&quot;</table>\n&quot;); 
print(&quot;</form>\n&quot;); 
 
?>

Q1. Actullay it's working :) But avoid the correpttion of images? Although text, php and html files are uplaoded successfuly!

Q2. I have to specify the file name, although if I only specify the path to the file in the browseer, it get uploaded successfuly, but it gave an error after that &quot;Permission Denied&quot; but it is uploaded correctly. How I can avoid specifying the file name?

So can u help me to get it working nicely?

BesT WiShEs

Ali
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top