Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Upload Script Can't Copy
Old 05-06-2005, 05:22 PM Upload Script Can't Copy
Skilled Talker

Posts: 61
Trades: 0
I modified an image uploading script I use on a few sites to upload excel and other documents, but for some reason I can't figure out to save my life, the fileName variable is not getting passed through when the form is submitted, so the copy function is failing. I've run out of things to test with no progress made.

Here's the source code:

PHP Code:
<table width="100%" cellpadding="0" cellspacing="5" border="0">
        <tr>
            <td class="boxTitle">ADD PROGRAM / RESOURCE</td>
        </tr>
        <tr>
            <td class="boxContent">
                <?
                $action 
$_POST['action'];
                
                if(
$action!="submitted"){
                    
?>
                    <form method="post" action="<? print($PHP_SELF); ?>" ENCTYPE="multipart/form-data" name="uploadProgram">
                    <input type="hidden" name="action" value="submitted">
                    <table cellpadding="5" cellspacing="0" border="0">
                    <tr>
                        <td><strong>Type</strong></td>
                        <td>
                            <select class="normal" name="type">
                            <option value="Document">Document (Excel, etc.)</option>
                            <option value="OtherSite">Other Website</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top"><strong>Other Site URI</strong></td>
                        <td>http://<input type="text" class="normal" size="63" name="URI"></td>
                    </tr>
                    <tr>
                        <td valign="top"><strong>Document File</strong></td>
                        <td><input type="file" class="normal" size="50" name="fileName"></td>
                    </tr>
                    <tr>
                        <td><strong>Title</strong></td>
                        <td><input type="text" size="70" class="normal" name="title"></td>
                    </tr>
                    <tr>
                        <td valign="top"><strong>Description</strong><br></td>
                        <td><textarea cols="80" rows="4" class="normal" name="description"></textarea></td>
                    </tr>
                    <tr><td colspan="2"><input type="submit" value=" add program " class="normalButton"></td></tr>
                    </table>
                    </form>
                    <?
                    
}
                else{
                    
                    
$type $_POST['type'];
                    
$title $_POST['title'];
                    
$fileName $_POST['fileName'];
                    
$description $_POST['description'];
                    
$URI $_POST['URI'];
                    
                    if(
$type=="OtherSite"){
                        
                        
$fileName $URI;
                        
                        
mysql_query("INSERT INTO programs VALUES (
                            '',
                            '
$title',
                            '
$description',
                            '
$type',
                            '
$fileName'
                            )"
);
                        
                        print(
'Program successfully added. <a href="index.php">Add Another &raquo;</a>');
                        
                        }
                    elseif(
$type=="Document"){
                        
                        if(empty(
$fileName)){
                            print 
'filename empty';
                            }
                        
                        
$uploadPath "../../programs/";
                        
                        
// MAKE NEW FILE NAME
                        
$fileNameForm str_replace(" """$fileName);
                        
                        
// NO FILE SELECTED
                        
if(!isset($HTTP_POST_FILES['fileName'])){
                            echo 
"Select a document file to upload";
                            }
                        
// CHECK IF IS UPLOADED FILE
                        
if(is_uploaded_file($HTTP_POST_FILES['fileName']['tmp_name'])){
                            
// FILE ALREADY EXISTS
                            
if(file_exists($uploadPath $HTTP_POST_FILES['fileName']['name'])){ 
                                echo 
"A file with that name already exists<br>\n"
                                }
                            
// COPY FILE TO DIRECTORY    
                            
$res copy($HTTP_POST_FILES['fileName']['tmp_name'], $uploadPath $fileNameForm);
                            
                            if(!
res){
                                echo 
'File Upload Failed! Please go back and try again.';
                                }
                            else{
                                
// INSERT INTO DB, PRINT SUCCESS
                                
mysql_query("INSERT INTO programs VALUES (
                                    '',
                                    '
$title',
                                    '
$description',
                                    '
$type',
                                    '
$fileNameForm'
                                    )"
);
                                print(
'Program successfully added. <a href="index.php">Add Another &raquo;</a>');
                                print(
'filename ' $fileName ', ' $fileNameForm);
                                }
                            
                            }
                    
                        }                    
                    
                    }
                
?>
            </td>
        </tr>
        <tr>
            <td class="boxTitle">PROGRAMS / RESOURCES ON RECORD</td>
        </tr>
        <tr>
            <td class="boxContent">
                <table width="100%" cellpadding="5" cellspacing="1" border="0">
                <tr>
                    <td bgcolor="#e5e5e5"><strong>Program / Resource</strong></td>
                    <td colspan="2" bgcolor="#e5e5e5" align="center"><img src="../../images/icons/checkmark.gif"><br></td>
                </tr>
                <?
                $resList 
mysql_query("SELECT * FROM programs ORDER BY title ASC");
                
$numList mysql_numrows($resList);
                
                for(
$iList 0$iList $numList$iList++){
                    
$programID mysql_result($resList,$iList,"programID");
                    
$title mysql_result($resList,$iList,"title");
                    
$fileName mysql_result($resList,$iList,"fileName");
                    
$type mysql_result($resList,$iList,"type");
                    
?>
                    <tr>
                        <td bgcolor="#ffffff">
                            <?
                            
if($type=="OtherSite"){
                                print(
'<a target="_blank" href="http://' $fileName '"><strong>' $title '</strong></a><br>');
                                }
                            elseif(
$type=="WebPage"){
                                print(
'<a target="_blank" href="/programs.php?show=program&programID=' $programID '"><strong>' $title '</strong></a><br>');
                                }
                            elseif(
$type=="Document"){
                                print(
'<a target="_blank" href="/programs/' $fileName '"><strong>' $title '</strong></a><br>');
                                }
                            
?>
                        </td>
                        <td bgcolor="#eeeeee" align="center">
                            <form method="post" action="edit_program.php"><input type="hidden" name="programID" value="<? print($programID); ?>">
                            <input type="image" src="/images/icons/button_edit.gif">
                            </form>    
                        </td>
                        <td bgcolor="#eeeeee" align="center">
                            <form method="post" action="delete_program.php"><input type="hidden" name="programID" value="<? print($programID); ?>">
                            <input type="image" src="/images/icons/button_delete.gif" onclick="javascript:return confirm('Are you sure you want to delete this program?')">
                            </form>    
                        </td>
                    </tr>
                    <?
                    
}            
                
?>
                </table>
            </td>
        </tr>
        </table>
Anyone have any ideas? Thanks.
gregory is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-07-2005, 02:22 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
You try to get $fileName from $_POST (here: $fileName = $_POST['fileName']; ), but it's wrong. The original name of uploaded file is stored in $_FILES['fileName']['name'] in your case.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 05-07-2005, 11:35 AM
Skilled Talker

Posts: 61
Trades: 0
That worked! Thanks a lot.
gregory is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Upload Script Can't Copy
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.07327 seconds with 12 queries