SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Athens, AL
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parse error, unexpected T_STRING

    I'm relatively new new to php, I'm using a book calles "SAMS Teach Yourself PHP, MySQL, and Apache in 24 Hours". It has many scripts for you to use to learn the 3. In doing a file upload script from the book and I keep getting the following error
    Code:
    Parse error: parse error, unexpected T_STRING in D:\Web Sites\practicesite\9.14.php on line 13
    Here are the scripts.
    Code:
    <html>
    <head>
    <title>Listing 9.13 A Simple File Upload Form</title>
    </head>
    <body>
    <form action="9.14.php" enctype="multipart/form-data" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="51200">
    File to Upload: <input type="file" name="fileupload"><br><br>
    <input type="submit" value="UPLOAD!">
    </form>
    </body>
    </html>
    And.
    Code:
    <html>
    <head>
    <title>Listing 9.14 A File Upload Script</title>
    </head>
    <body>
    <h1>
    File Upload Results
    </h1>
    <?php
    $file_dir = "\uploadedfiles\";
    
    foreach($_FILES as $file_name => $file_array) {
    	print "path: "$file_array['tmp_name']"<br>\n";
    	print "name: "$file_array['name']"<br>\n";
    	print "type: "$file_array['type']"<br>\n";
    	print "size: "$file_array['size']"<br>\n";
    	
    	if (is_uploaded_file($file_array['tmp_name'])) {
    		move_uploaded_file($file_array['tmp_name'],
    			"$file_dir/$file_array[name]") or die ("Couldn't copy");
    		print "file was moved!<br><br>";
    	}
    }
    ?>
    </body>
    </html>
    Can someone please help me correct this error.

    Thanks,
    Taylor

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Madison, WI
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you need to have dots around your array references, like so:
    PHP Code:
    print "path: ".$file_array['tmp_name']."<br>\n";
    // etc... 

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    San Diego, CA (USA)
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    instead of
    PHP Code:
    $file_dir "\uploadedfiles\"; 
    try:
    PHP Code:
    $file_dir "/uploadedfiles"
    also instead of:
    PHP Code:
    print "path: "$file_array['tmp_name']"<br>\n";
    print 
    "name: "$file_array['name']"<br>\n";
    print 
    "type: "$file_array['type']"<br>\n";
    print 
    "size: "$file_array['size']"<br>\n"
    try:
    PHP Code:
    print "path: ".$file_array['tmp_name']."<br>\n";
    print 
    "name: ".$file_array['name']."<br>\n";
    print 
    "type: ".$file_array['type']."<br>\n";
    print 
    "size: ".$file_array['size']."<br>\n"

  4. #4
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Athens, AL
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I fixed what you told me and now I don't get the error but it still won't upload the file I want. Could there be an issue in the php.ini file i need to change.

    Please help me.

    Thanks,
    Taylor


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •