42 users online (0 members and 42 guests)  


  Results 1 to 15 of 15

Related

  1. Upload Script    Forum: PHP Forum
    Replies: 1
  2. [split] PHP upload script.    Forum: PHP Forum
    Replies: 3
  3. PHP upload script.    Forum: PHP Forum
    Replies: 4
  4. php upload script needed..    Forum: PHP Forum
    Replies: 5
  5. Script to allow users to upload pics    Forum: Website Scripts Forum
    Replies: 2
  1. #1
    Danal's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2004
    Location
    Calgary
    Posts
    7

    PHP Upload script error

    Hey Im pretty new to this PHP and ive making a website that has a collection of pictures of my freinds and all, and I was hoping to make it so each user could submit their own but the code I have keeps giving me errors, and I think it may be that my folder isnt CHModded to 777, im unaware of how to do that
    this is what i have so far



    <?php $title = "Upload Pics"; include("header.php"); ?>
    <HTML>
    <HEAD>
    <TITLE>Uploading files with PHP.</TITLE>
    </HEAD>
    <BODY>
    <FORM method="POST" action="do-upload.php" enctype="multipart/form-data">
    <P align="center"><FONT size="4">Upload a File</font></p>
    <p>Please select a file</p>
    <input type="file" name="upload-file">
    <p><input type="submit" value="Upload File!"></p>
    </FORM>

    </BODY>
    </HTML>
    <HTML><HEAD>
    <TITLE>Uploading your file</TITLE>
    </HEAD>
    <BODY>
    <P><FONT size="4">
    <?php
    $Path = "/home/justin56/public_html";
    if(copy($_FILES['upload-file']['tmp_name'], $Path.'/'.$_FILES['upload-file']['name'])){

    echo 'File Uploaded Successfully';

    }else{

    echo 'File could not be uploaded';

    }

    ?>

    </FONT></P>
    </BODY>
    </HTML>
    <?php include("footer.php"); ?>
    Last edited by Danal; 03-29-2004 at 02:00 PM. Reason: missed what i was gonna put in it

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    You can chmod with most FTP programs. Check out the Help section of the FTP client you use.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    Danal's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2004
    Location
    Calgary
    Posts
    7
    Quote Originally Posted by QuietDean
    You can chmod with most FTP programs. Check out the Help section of the FTP client you use.
    O yes I found it thank you, lets just hope my script now works

  4. #4
    Danal's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2004
    Location
    Calgary
    Posts
    7
    does anyone else see what my error is on line 23 I think it lies in the $_FILES line somewhere

    thanks for any help.

  5. #5
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    How do you expect us to try and help you with an error if you dont post what the error is?
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  6. #6
    Danal's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2004
    Location
    Calgary
    Posts
    7

    sorry

    i was quite angry i forgot its an error on line 23

    Warning: copy(): Unable to access in /home/justin56/public_html/upload2.php on line 23

    I think it has something to do with $_FILES
    i heard that dosent work well when copying files

  7. #7
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Try using the simple example from here: http://uk.php.net/manual/en/features.file-upload.php

    It uses move_uploaded_file , so if it works we will amend your original script to use it.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  8. #8
    Danal's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2004
    Location
    Calgary
    Posts
    7
    hmm, im not sure which part of that to use, im brand new in php and i dont understand much of that

  9. #9
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    This bit -

    Code:
    <?php
    // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
    // of $_FILES.
    
    $uploaddir = '/var/www/uploads/';
    $uploadfile = $uploaddir . $_FILES['userfile']['name'];
    
    print "<pre>";
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
       print "File is valid, and was successfully uploaded. ";
       print "Here's some more debugging info:\n";
       print_r($_FILES);
    } else {
       print "Possible file upload attack!  Here's some debugging info:\n";
       print_r($_FILES);
    }
    print "</pre>";
    
    ?>
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  10. #10
    Danal's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2004
    Location
    Calgary
    Posts
    7

    fixed problem

    i got the problem fixed, now it just wont let me update the DB

    $name = $_FILES["userfile"]["tmp_name"];
    $desc = $_REQUEST[desc];
    $loads = $stat[uploads];
    if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
    copy($_FILES["userfile"]["tmp_name"], "images/" . $_FILES["userfile"]["name"]);
    mysql_query("INSERT INTO pics(desc,file,upload)VALUES('$desc','$name','{$stat[user]}')");
    mysql_query("update players set uploads='" . $loads+1 . "' where id={$stat[id]}");
    echo("<p>$name uploaded successfully.</p>");
    echo("<p>$desc</p>");
    }


    the databases wont change anything, but the img uploads
    Last edited by Danal; 03-31-2004 at 10:09 PM. Reason: fixed problem

  11. #11
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Hi,

    mySQL errors are silent in PHP by default, so we need to add some error reporting.
    For each query, try this format -

    Code:
    if (!$result = mysql_query("SQL Etc.."))
    {
    echo mysql_error();
    } else {
    echo "Succeeded";
    }
    See if that reports any errors.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  12. #12
    Danal's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2004
    Location
    Calgary
    Posts
    7
    You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SQL Etc..' at line 1


    Hmm, i cant seem to find an error in line 1

  13. #13
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    You have to replace the 'SQL Etc...' part with your own SQL code.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  14. #14
    Titatovenaar's Avatar
    New User

    Status
    Offline
    Join Date
    Aug 2004
    Posts
    1

    Trying to make ya upload script work

    Hi all!

    I have downloaded and (tried) to implement an upload script I found here. The code is as follows :

    Code:
    function UpdateFoto()
    	{
    	global $FileToUpload, $uploaddir, $uploadfile;
    	$uploaddir = '/var/www/html/uploads/';
    	$uploadfile = $uploaddir . $_FILES['userfile']['name'];
    	print "<pre>"; 
    	if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
    		{ print "File is valid, and was successfully uploaded. "; 
    		  print "Here's some more debugging info:\n"; 
    		  print_r($_FILES);
    		} 
    	else { print "Possible file upload attack! Here's some debugging info:\n"; 
    		 print_r($_FILES); } 
    	print "</pre>";
    
    	CurrentFoto();
    	}
    The uploaddir is vaialable, and chmodded to 777. But, alas, I get the following error :

    Possible file upload attack! Here's some debugging info:
    Array
    (
    [FileToUpload] => Array
    (
    [name] => cod.jpg
    [type] => image/pjpeg
    [tmp_name] => /tmp/phpqkBvzg
    [error] => 0
    [size] => 3232
    )

    )
    Could you give me a clue, as to where the possible cause lies?

    Greetz,

    Tita

  15. #15
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel
    please start your own thread.

    Dave



Tags for this Thread