SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 42

Thread: Need some help!

  1. #1
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need some help!

    I need the following code to put a random number onto the file name. Like say you upload image.jpg, I want it to be like 213image.jpg after its uploaded. So that I dont have to worry about people getting the re-name your image error. Any help would be awsome! Here is the code.

    PHP Code:
    <?
    //set these variables-----------------------------------------------------------------
    $path "test/uploads/";   //path to your targetfolder after your domain
    $max_size 1000000;          //maximum filesize

    //optionally
    $domain $_SERVER["HTTP_HOST"];      //your domainname - change if necessary like "www.wza.be"

    //------------------------------------------------------------------------------------
    ?>

    <?

    if (!isset($HTTP_POST_FILES['userfile'])) exit;

    if (
    is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {

    if (
    $HTTP_POST_FILES['userfile']['size']>$max_size) {
            echo 
    "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">File is too big !</font><br>\n"; exit; }
    if ((
    $HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) {

            if (
    file_exists("../".$path $HTTP_POST_FILES['userfile']['name'])) {
                    echo 
    "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">There already exists a file with this name, please rename your file and try again</font><br>\n"; exit; }

            
    $res copy($HTTP_POST_FILES['userfile']['tmp_name'], "../".$path .$HTTP_POST_FILES['userfile']['name']);

            if (!
    $res) { echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">Didn't work, please try again</font><br>\n"; exit; } else {
            
    ?>
    <br>
    <p> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><strong>Find 
              your file here: </strong></font><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif"><strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br>
              </a></font></strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><font color="#B6B66D">http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?></font></a><strong><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br>
              </a></strong></font><br>
              <strong><font color="#FFFFFF">HTML:</font></strong><br>
              <font color="#B6B66D">&lt;img src=&quot;http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>&quot;&gt;</font><br>
      <br>
              <font color="#FFFFFF"><strong>BBCode: </strong><strong></strong></font><font color="#990000"><strong><br>
              </strong> <font color="#B6B66D">[img]http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>[/img]</font></font></font></p>
    <?
     
    }
    echo 
    "<font color=\"#B6B66D\" face=\"Geneva, Arial, Helvetica, sans-serif\"><hr>";
    echo 
    "Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n";
    echo 
    "Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n";
    echo 
    "Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n";
    echo 
    "</font>";
    }

    }

    ?>
    Hexation Media
    SpeedyUploads.Com - Free Image Hosting Services.

  2. #2
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While uploading an image use file name like this
    $filename=uniqid('').$HTTP_POST_FILES['Attachment']['name'];

  3. #3
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Arg, any chance you could edit what I have with that in it? I really dont know PHP, and im having trouble getting it to work.
    Hexation Media
    SpeedyUploads.Com - Free Image Hosting Services.

  4. #4
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Try this

    PHP Code:
    <?
    if (!isset($HTTP_POST_FILES['userfile'])) exit; 

    if (
    is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) 


        if (
    $HTTP_POST_FILES['userfile']['size']>$max_size
        { 
                echo 
    "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">File is too big !</font><br>\n"; exit; } 
            if ((
    $HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) 
            { 
            
                
    //here we are uploadin the file         
                
    if($_FILES['userfile']['tmp_name']!='')
                    {
                        
    $uploadpath="../Attachment/";  // THIS IS PATH/FOLDER NAME WHRER FILE IS UPLOADED 
                        
    $source=$_FILES['userfile']['tmp_name'];
                    
                        
    $filename=uniqid('').$HTTP_POST_FILES['userfile']['name'];
                       
    // $filename=$user_name.$HTTP_POST_FILES['Attachment']['name'];
                        
    $uploadpath=$uploadpath.$filename;
                        if((
    move_uploaded_file($source,$uploadpath)==false) && (strlen($_REQUEST['userfile'])!=0))
                        {
                            echo 
    "file can not be uploaded";
                            exit(
    0);
                        }
                    }
                    else
                    {
                        
    $filename="";
                    }
            }
        }

  5. #5
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Boy am I confused. So how would I put that into what I have already?
    Hexation Media
    SpeedyUploads.Com - Free Image Hosting Services.

  6. #6
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    replace it and try , if u found any bug just let me know

  7. #7
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In that code I haven’t done any big changes , its just small thing u can understand it clearly but if u stuck let me know

  8. #8
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I just replace it, it would take away the output I still want. Or should I just replace certain parts?
    Hexation Media
    SpeedyUploads.Com - Free Image Hosting Services.

  9. #9
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just take a look at following line

    $filename=uniqid('').$HTTP_POST_FILES['userfile']['name'];

  10. #10
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    OK-- here we go

    PHP Code:
    <? 
    //set these variables----------------------------------------------------------------- 
    $path "test/uploads/";   //path to your targetfolder after your domain 
    $max_size 1000000;          //maximum filesize 

    //optionally 
    $domain $_SERVER["HTTP_HOST"];      //your domainname - change if necessary like "www.wza.be" 

    //------------------------------------------------------------------------------------ 
    ?> 

    <? 

    if (!isset($HTTP_POST_FILES['userfile'])) exit; 

    if (
    is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) { 

    if (
    $HTTP_POST_FILES['userfile']['size']>$max_size) { 
            echo 
    "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">File is too big !</font><br>\n"; exit; } 
    if ((
    $HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) { 

            if (
    file_exists("../".$path $HTTP_POST_FILES['userfile']['name'])) { 
                    echo 
    "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">There already exists a file with this name, please rename your file and try again</font><br>\n"; exit; } 

            
    $res copy($HTTP_POST_FILES['userfile']['tmp_name'], "../".$pathuniqid('').$HTTP_POST_FILES['userfile']['name']); 

            if (!
    $res) { echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">Didn't work, please try again</font><br>\n"; exit; } else { 
            
    ?> 
    <br> 
    <p> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><strong>Find 
              your file here: </strong></font><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif"><strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br> 
              </a></font></strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><font color="#B6B66D">http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?></font></a><strong><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br> 
              </a></strong></font><br> 
              <strong><font color="#FFFFFF">HTML:</font></strong><br> 
              <font color="#B6B66D">&lt;img src=&quot;http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>&quot;&gt;</font><br> 
      <br> 
              <font color="#FFFFFF"><strong>BBCode: </strong><strong></strong></font><font color="#990000"><strong><br> 
              </strong> <font color="#B6B66D">[img]http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>[/img]</font></font></font></p> 
    <? 

    echo 
    "<font color=\"#B6B66D\" face=\"Geneva, Arial, Helvetica, sans-serif\"><hr>"
    echo 
    "Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n"
    echo 
    "Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n"
    echo 
    "Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n"
    echo 
    "</font>"




    ?>

  11. #11
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OOOOOOOOOOOO, Wow I feal stupid now. I see, gunna go try it now. Thank you SO much!
    Hexation Media
    SpeedyUploads.Com - Free Image Hosting Services.

  12. #12
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok doesnt seem to work still shows "
    There already exists a file with this name, please rename your file and try again" after I try to upload.
    Hexation Media
    SpeedyUploads.Com - Free Image Hosting Services.

  13. #13
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok so I took out

    PHP Code:
    if (file_exists("../".$path $HTTP_POST_FILES['userfile']['name'])) {
                    echo 
    "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">There already exists a file with this name, please rename your file and try again</font><br>\n"; exit; } 
    So now anything will upload and it doesnt do the check. But it still doesnt put a random name on after its uploaded. I used exactly what you posted.
    Hexation Media
    SpeedyUploads.Com - Free Image Hosting Services.

  14. #14
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whats in $path

  15. #15
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    This code is working , i checked it

    PHP Code:
    <? 
    //set these variables----------------------------------------------------------------- 
    $path "test/uploads/";   //path to your targetfolder after your domain 
    $max_size 1000000;          //maximum filesize 

    //optionally 
    $domain $_SERVER["HTTP_HOST"];      //your domainname - change if necessary like "www.wza.be" 

    //------------------------------------------------------------------------------------ 
    ?> 

    <? 

    if (!isset($HTTP_POST_FILES['userfile'])) exit; 

    if (
    is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) { 

    if (
    $HTTP_POST_FILES['userfile']['size']>$max_size) { 
            echo 
    "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">File is too big !</font><br>\n"; exit; } 
    if ((
    $HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) { 

            if (
    file_exists("../".$path $HTTP_POST_FILES['userfile']['name'])) { 
                    echo 
    "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">There already exists a file with this name, please rename your file and try again</font><br>\n"; exit; } 

            
    $res copy($HTTP_POST_FILES['userfile']['tmp_name'], "../".$pathuniqid('').$HTTP_POST_FILES['userfile']['name']); 

            if (!
    $res) { echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">Didn't work, please try again</font><br>\n"; exit; } else { 
            
    ?> 
    <br> 
    <p> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><strong>Find 
              your file here: </strong></font><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif"><strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br> 
              </a></font></strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><font color="#B6B66D">http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?></font></a><strong><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br> 
              </a></strong></font><br> 
              <strong><font color="#FFFFFF">HTML:</font></strong><br> 
              <font color="#B6B66D">&lt;img src=&quot;http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>&quot;&gt;</font><br> 
      <br> 
              <font color="#FFFFFF"><strong>BBCode: </strong><strong></strong></font><font color="#990000"><strong><br> 
              </strong> <font color="#B6B66D">[img]http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>[/img]</font></font></font></p> 
    <? 

    echo 
    "<font color=\"#B6B66D\" face=\"Geneva, Arial, Helvetica, sans-serif\"><hr>"
    echo 
    "Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n"
    echo 
    "Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n"
    echo 
    "Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n"
    echo 
    "</font>"




    ?>

  16. #16
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    its working

    PHP Code:
    $path="images/";
    if (!isset($HTTP_POST_FILES['userfile'])) exit; 

    if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) { 

    if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) { 

            if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { 
                    echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">There already exists a file with this name, please rename your file and try again</font><br>\n"; exit; } 

            $res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path.$HTTP_POST_FILES['userfile']['name']); 

            if (!$res) { echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">Didn't work, please try again</font><br>\n"; exit; } else { 
            ?> 
    <br> 
    <p> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><strong>Find 
              your file here: </strong></font><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif"><strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br> 
              </a></font></strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><font color="#B6B66D">http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?></font></a><strong><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br> 
              </a></strong></font><br> 
              <strong><font color="#FFFFFF">HTML:</font></strong><br> 
              <font color="#B6B66D">&lt;img src=&quot;http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>&quot;&gt;</font><br> 
      <br> 
              <font color="#FFFFFF"><strong>BBCode: </strong><strong></strong></font><font color="#990000"><strong><br> 
              </strong> <font color="#B6B66D">[img]http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>[/img]</font></font></font></p> 
    <? 

    echo 
    "<font color=\"#B6B66D\" face=\"Geneva, Arial, Helvetica, sans-serif\"><hr>"
    echo 
    "Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n"
    echo 
    "Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n"
    echo 
    "Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n"
    echo 
    "</font>"


    }

  17. #17
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just updated it on http://speedyuploads.com/site/uploaded.php and it doesnt do it. Please check..
    Hexation Media
    SpeedyUploads.Com - Free Image Hosting Services.

  18. #18
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    All in one

    <form action="upload.php" method="post" enctype="multipart/form-data">
    <input name="userfile" type="file">
    <input name="click" type="submit">
    </form>


    ------------------------------------------------------------
    upload.php
    ------------------------------------------------------------
    PHP Code:
    <? 

    $path
    ="images/";
    if (!isset(
    $HTTP_POST_FILES['userfile'])) exit; 

    if (
    is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) { 

    if ((
    $HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) { 

            if (
    file_exists($path $HTTP_POST_FILES['userfile']['name'])) { 
                    echo 
    "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">There already exists a file with this name, please rename your file and try again</font><br>\n"; exit; } 

            
    $res copy($HTTP_POST_FILES['userfile']['tmp_name'], $path.uniqid('').$HTTP_POST_FILES['userfile']['name']); 

            if (!
    $res) { echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">Didn't work, please try again</font><br>\n"; exit; } else { 
            
    ?> 
    <br> 
    <p> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><strong>Find 
              your file here: </strong></font><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif"><strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br> 
              </a></font></strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><font color="#B6B66D">http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?></font></a><strong><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br> 
              </a></strong></font><br> 
              <strong><font color="#FFFFFF">HTML:</font></strong><br> 
              <font color="#B6B66D">&lt;img src=&quot;http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>&quot;&gt;</font><br> 
      <br> 
              <font color="#FFFFFF"><strong>BBCode: </strong><strong></strong></font><font color="#990000"><strong><br> 
              </strong> <font color="#B6B66D">[img]http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>[/img]</font></font></font></p> 
    <? 

    echo 
    "<font color=\"#B6B66D\" face=\"Geneva, Arial, Helvetica, sans-serif\"><hr>"
    echo 
    "Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n"
    echo 
    "Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n"
    echo 
    "Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n"
    echo 
    "</font>"




    ?>

  19. #19
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try above and let me know

  20. #20
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is above code working @ ur end ?

  21. #21
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It still shows
    There already exists a file with this name, please rename your file and try again when I try to upload the same file. I want to so even if they upload the same file name they wont get the error, it will change it or add a number on it.
    Hexation Media
    SpeedyUploads.Com - Free Image Hosting Services.

  22. #22
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Whts the out put in this case

    Try this
    Create one file with name “file.php” kkep following code in it :
    <form action="upload.php" method="post" enctype="multipart/form-data">
    <input name="userfile" type="file">
    <input name="click" type="submit">
    </form>

    Now create another file with name “upload.php” and put following code in it

    PHP Code:
    <? 

    $path
    =" test/uploads/ ";
    if (!isset(
    $HTTP_POST_FILES['userfile'])) exit; 

    if (
    is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) { 

    if ((
    $HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) { 

            if (
    file_exists($path $HTTP_POST_FILES['userfile']['name'])) { 
                    echo 
    "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">There already exists a file with this name, please rename your file and try again</font><br>\n"; exit; } 

            
    $res copy($HTTP_POST_FILES['userfile']['tmp_name'], $path.uniqid('').$HTTP_POST_FILES['userfile']['name']); 

            if (!
    $res) { echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">Didn't work, please try again</font><br>\n"; exit; } else { 
            
    ?> 
    <br> 
    <p> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><strong>Find 
              your file here: </strong></font><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif"><strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br> 
              </a></font></strong><font color="#990000"><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><font color="#B6B66D">http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?></font></a><strong><a href="http://<? echo $domain?>/<? echo "../".$path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br> 
              </a></strong></font><br> 
              <strong><font color="#FFFFFF">HTML:</font></strong><br> 
              <font color="#B6B66D">&lt;img src=&quot;http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>&quot;&gt;</font><br> 
      <br> 
              <font color="#FFFFFF"><strong>BBCode: </strong><strong></strong></font><font color="#990000"><strong><br> 
              </strong> <font color="#B6B66D">[img]http://<? echo $domain?>/<? echo $path?><? echo $HTTP_POST_FILES['userfile']['name']; ?>[/img]</font></font></font></p> 
    <? 

    echo 
    "<font color=\"#B6B66D\" face=\"Geneva, Arial, Helvetica, sans-serif\"><hr>"
    echo 
    "Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n"
    echo 
    "Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n"
    echo 
    "Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n"
    echo 
    "</font>"




    ?>

  23. #23
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is above is still creating same err

  24. #24
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Warning: copy(http://www.speedyuploads.com/site/up...378a6078bl.jpg) [function.copy]: failed to open stream: HTTP wrapper does not support writeable connections. in /home/speedyup/public_html/site/upload.php on line 121
    Didn't work, please try again

    Whats this mean? Also I had to put the full urle in the path
    Hexation Media
    SpeedyUploads.Com - Free Image Hosting Services.

  25. #25
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok somewhere along the lines this was correct. The reason I didnt notice was because the output to the screen, where it shows the image location, size, type wasnt changing with the new file name.
    Hexation Media
    SpeedyUploads.Com - Free Image Hosting Services.


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
  •