LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-30-2005, 06:51 PM   #1
Phaux
LQ Newbie
 
Registered: Dec 2005
Location: Here.
Distribution: Ubuntu 7.04 Server
Posts: 13

Rep: Reputation: 0
PHP 4.4.0 Coding Error


I have a bit of a problem with my code. I am trying to set up a simple way to upload a file, and by able to view it publicly. This script should be able to:
1) Accept the file and add random 3-digit prefix (nnnfile.txt)
2) Check if nnnfile.txt exists
2A) If it does, change the prefix to a 4-digit prefix (nnnnfile.txt)
2B) If it doesn't, move it from /tmp/php to /var/www/phaux.ath.cx/htdocs/uploads
3) Make a varible $file to the files location.

Simple? Heres the code. When I run it, it spits out:
Quote:
Parse error: parse error, unexpected $ in /var/www/phaux.ath.cx/htdocs/upload.php on line 21
Count the lines and tell me whats wrong with this script.

PHP Code:
<?php require('/inc/header.inc'?>

<?php
  $uploadfolder 
"/var/www/phaux.ath.cx/htdocs/uploads/";
  
$rand1 rand(100999);
  if(
is_uploaded_file($_FILES['uploaded']['tmp_name'])) {
    if(
file_exists("{$uploadfolder}{$rand1}{$_FILES['uploaded']['name']}")) {
      
$rand2 rand(10009999);
      
move_uploaded_file($_FILES['uploaded']['tmp_name'], "{$uploadfolder}{$rand2}{$_FILES['uploaded']['name']}");
      
$file "{$uploadfolder}{$rand2}{$_FILES['uploaded']['name']}";
    } else {
    
move_uploaded_file($_FILES['uploaded']['tmp_name'], "{$uploadfolder}{$rand1}{$_FILES['uploaded']['name']}");
    
$file "{$uploadfolder}{$rand1}{$_FILES['uploaded']['name']}";
  }
?>

<FORM METHOD="POST" ACTION="upload.php" ENCTYPE="multipart/form-data">
  <INPUT TYPE="file" NAME="uploaded"> <INPUT TYPE="submit" VALUE="Upload">
</FORM>
<?php require('/inc/footer.inc'?>
Notice how theres no line 21?
 
Old 12-30-2005, 07:05 PM   #2
Phaux
LQ Newbie
 
Registered: Dec 2005
Location: Here.
Distribution: Ubuntu 7.04 Server
Posts: 13

Original Poster
Rep: Reputation: 0
Nevermind, I fixed it. I found the end bracket on line 14 was missing.

PHP Code:
<?php require('/inc/header.inc'?>

<?php
  $uploadfolder 
"/var/www/phaux.ath.cx/htdocs/uploads/";
  
$rand1 rand(100999);
  if(
is_uploaded_file($_FILES['uploaded']['tmp_name'])) {
    if(
file_exists("{$uploadfolder}{$rand1}{$_FILES['uploaded']['name']}")) {
      
$rand2 rand(10009999);
      
move_uploaded_file($_FILES['uploaded']['tmp_name'], "{$uploadfolder}{$rand2}{$_FILES['uploaded']['name']}");
      
$file "{$uploadfolder}{$rand2}{$_FILES['uploaded']['name']}";
    } else {
    
move_uploaded_file($_FILES['uploaded']['tmp_name'], "{$uploadfolder}{$rand1}{$_FILES['uploaded']['name']}");
    
$file "{$uploadfolder}{$rand1}{$_FILES['uploaded']['name']}";
    }
  }
?>

<FORM METHOD="POST" ACTION="upload.php" ENCTYPE="multipart/form-data">
  <INPUT TYPE="file" NAME="uploaded"> <INPUT TYPE="submit" VALUE="Upload">
</FORM>
<?php require('/inc/footer.inc'?>
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding java in a php script mrobertson Programming 44 06-27-2005 01:16 PM
Coding a redirect function in php mrobertson Programming 2 06-22-2005 08:40 AM
coding a php server mrobertson Linux - General 22 06-05-2005 01:06 PM
php coding with knoppix mrobertson Linux - General 1 06-01-2005 01:30 PM
vim php color coding? Longinus Linux - Software 4 04-11-2004 05:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration