Current location: Hot Scripts Forums » Programming Languages » PHP » uploading problem


uploading problem

Reply
  #1 (permalink)  
Old 07-31-04, 03:44 AM
stealth04 stealth04 is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
uploading problem

Hi,
I am doing an example from Wrox Press Professional PHP programming. I have rewritten the code from book, but it doesn't work.
I would like to upload the txt file and name it with applicant's name.
Here is the piece of code that doesn't work as it should:
PHP Code:

if ($userfile)

{
    if(
copy($userfile"/temp/$applicant"))
    {
        echo 
"<B>Resume recieved: thank you!</B>";
    }
    else 
    {
        echo 
"<B>Error saving resume.</B>".
        
"However, your application will still be processed.";
    }

then I tried to write $applicant.txt instead $applicant and of course I have created the directory called temp, but is still get this:
Warning: copy(/temp/Niko.txt): failed to open stream: No such file or directory in c:\appserv\www\learning\jobapp action.php on line 72

This is a code from the book. Could anyone help me to find an error or write the code for file upload (and name a file after $variable) in different way?
Thank you
Reply With Quote
  #2 (permalink)  
Old 07-31-04, 09:45 AM
Tim Tim is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
$userfile = $_FILES['userfile']['tempname'];

if (is_uploaded_file($userfile))
{
// Rename File
$splitname = explode(".",$_FILES['userfile']['name']);
$newname = "$applicant" . "." . "$splitname[1]";

if(move_uploaded_file($_FILES['userfile']['tmp_name'], "/temp/" . "$newname"))
{
echo "<B>Resume recieved: thank you!</B>";
}
else
{
echo "<B>Error saving resume.</B>".
"However, your application will still be processed.";
}
}

This is how I would do it. You would also want to validate the file type of course.
__________________
Tim
Reply With Quote
  #3 (permalink)  
Old 07-31-04, 12:41 PM
stealth04 stealth04 is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
I have found an error. Thank you anyway
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie found a solution to a date problem. mickey_kamer Perl 4 05-09-07 05:54 AM
Error in uploading image~ HELP!! violet ASP 1 03-31-05 09:28 AM
Count problem kasic ASP.NET 1 10-20-04 12:23 AM
an unusual problem.... fabulosas10 PHP 0 07-16-04 02:03 AM
problem with uploading image mivec PHP 6 04-15-04 11:52 PM


All times are GMT -5. The time now is 04:17 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.