Originally posted by matt_4013
Rather than using rename, try move_uploaded_file() like so:

if(!file_exists($tmpfile)) {

move_uploaded_file($_FILES['myfile']['tmp_name'],  $tmp_name);

} else { 

unlink($tmpfile);
move_uploaded_file($_FILES['myfile']['tmp_name'],  $tmp_name);
}

[/B]

Thanks, that worked.

Any reason why the "rename" wouldn't work? Or is it just one of those "old" vs "new" or just the difference between how apache/win and apaceh/linux works?

    piss off.....

    maybe if you weren't such an ass with no humor, i wouldn't have a problem with you, we are all here for help, to help, and do it in good fun, and bashing on my posts when you are reading in on an afterthought is just tasteless and unneeded

      Any reason why the "rename" wouldn't work? Or is it just one of those "old" vs "new" or just the difference between how apache/win and apaceh/linux works?

      yeah, rename doesn't work on cross-platform files. It's something to do with being thread safe, never really looked into it that much. Anyway, it's better to use move_uploaded_file() because it checks to make sure that the file WAS actually uploaded via a http request, if it wasn't it returns false. Just a little extra security feature. You could also use the copy() function and the unlink() function if you don't want this behaviour.

        Originally posted by stolzyboy
        piss off.....

        maybe if you weren't such an ass with no humor, i wouldn't have a problem with you, we are all here for help, to help, and do it in good fun, and bashing on my posts when you are reading in on an afterthought is just tasteless and unneeded

        Maybe if you weren't such a linux/apache fanboy and get off that high pedestal you put yourself on, and come down to the real world, you'd know that not everything revolves around linux/apache.

        And again, why aren't you offering answers? hmm? Still have to demean others i see....if you have nothing worthwhile to post, dont post at all.

          Originally posted by matt_4013
          yeah, rename doesn't work on cross-platform files. It's something to do with being thread safe, never really looked into it that much. Anyway, it's better to use move_uploaded_file() because it checks to make sure that the file WAS actually uploaded via a http request, if it wasn't it returns false. Just a little extra security feature. You could also use the copy() function and the unlink() function if you don't want this behaviour.

          matt, thanks for the code but something odd is happening.

          IT worked, but now Im getting errors:

          Warning: Unable to create '': No such file or directory in /var/www/html/employee/admin_picupload.php on line 44

          Warning: Unable to move '/tmp/php0Nf5jZ' to '' in /var/www/html/employee/admin_picupload.php on line 44

          Warning: Cannot add header information - headers already sent by (output started at /var/www/html/employee/admin_picupload.php:44) in /var/www/html/employee/admin_picupload.php on line 60

            to get rid of the header error, you can try putting

            <?
            ob_start();
            ?>

            at the top of the page, that error is created cuz you have output before you call the header function

            as for the others, make sure php has sufficient permissions to
            upload to the directory you want to upload to

              High post count does not mean helpful posts. So what if yu have 1000 if 99% of them are attacking others, you did jack to help. Seeng the trend in this thread, you really have nothing to offer.

              So why dont you go an pick on somene who gives?

              Seeing you can't even answer the questions I've posted, you're "expertise" is duely noted.

                why don't you look up to the post before yours

                maybe i shouldn't help your dumb arse

                  Originally posted by stolzyboy
                  to get rid of the header error, you can try putting

                  <?
                  ob_start();
                  ?>

                  at the top of the page, that error is created cuz you have output before you call the header function

                  as for the others, make sure php has sufficient permissions to
                  upload to the directory you want to upload to

                  Now was that so hard? _

                  Permissions are set to chmod 777 on all folders until it works.

                  I think it has to do with a non-specified, temp directory in the php.ini file (I have no access to)

                  is there a way to "designate" a tmp upload folder and make the script move it from there?

                    Originally posted by stolzyboy
                    why don't you look up to the post before yours

                    maybe i shouldn't help your dumb arse

                    Hey, I was answering a post YOU edited apparently that was about how your high post count = to your helpfulness.

                      not too sure, i'm thinking that the php.ini is the only way to do it,
                      you may be able to do it with .htaccess, not sure how

                      did the ob_start get rid of the header error

                        Actually, now Im getting a 404 page when the script executes with that in the opening page.

                        the last "line" is to redirect to another page after upload, so i have
                        header("Location: admin_employee.php");

                        And that's what was giving the error , only because the upload script wasn't "moving" the uploaded file from "the unknown" tmp directory to the directory where I need the image.

                        //The file to be uploaded
                        $tmpfile = "images/emps/".$myfile_name;
                        
                        
                        if(!file_exists($tmpfile)) {
                        move_uploaded_file($_FILES['myfile']['tmp_name'],  $tmp_name);
                        } else { 
                        unlink($tmpfile);
                        move_uploaded_file($_FILES['myfile']['tmp_name'],  $tmp_name);
                        }
                        
                        //Update the database table for the new record
                        $uSQL = "update emps set picture='$myfile_name' where emp_id=".get_param("emp_id");
                         $db->query($uSQL);
                        
                        // Redirect the user to the admin_employees.php page
                        header("Location: admin_employee.php");
                        

                        this error is driving me nuts:

                        Warning: Unable to create '': No such file or directory in /var/www/html/employee/admin_picupload.php on line 24

                        Warning: Unable to move '/tmp/phphgq90X' to '' in /var/www/html/employee/admin_picupload.php on line 24

                        Warning: Cannot add header information - headers already sent by (output started at /var/www/html/employee/admin_picupload.php:24) in /var/www/html/employee/admin_picupload.php on line 35

                        ( the last line is that header() redirect line)

                        AND I dont know why it WAS working yesterday, when matt first gave the code, but after I closed down the browsers, and went back to it, it doesn't work.

                          hmmm.......sorry man don't know what to tell ya, not to familiar
                          with the move uploaded file, i generally use the copy and unlink
                          route

                            heh, look at the names of the variables man, $tmp_name isn't set, so it's empty. Change to

                            move_uploaded_files($_FILES['myfile']['tmp_name'], $tmpfile);

                            🙂

                              btw, the header problem was happening because the errors from the upload were outputting to the browser. There's no need to use output buffering.

                                there may be no need to use ob, but it will suppress the header problems

                                  Originally posted by WizyWyg
                                  Upload php script:

                                  [B]<?
                                  ...
                                  //The file to be uploaded
                                  $tmpfile = "images/emps/".$myfile_name;
                                  
                                  if (!file_exists($tmpfile)) {
                                  rename($myfile,$tmpfile);
                                  } else {
                                  unlink($tmpfile);
                                  rename($myfile,$tmpfile);
                                  }
                                  ...
                                  

                                  [/B]

                                  Hey WizyWyg, I don't know if it will be helpful but consider using

                                  $HTTP_POST_FILES['myfile']['xxx']
                                  

                                  rather than

                                  $myfile_name
                                  
                                    Write a Reply...