mercredi 25 novembre 2015

PHP function RAND and a variable

Hello I'm testing a code and one of the problems that I've got is that rand() is generating 2 different results. Its uploading the picture with one name, but its echoing other random name. I've tried all possible scenarios and i can't get it to work... All I want is to get the actual picname and echo one to be the same.

I know that the code is full with other errors :)

<div class="modal fade" id="PicsUp" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
   <div class="modal-dialog" role="document"> <?php 
    // $new_name = sha1(mt_rand()).'.jpg';
    $gosho = rand(1,9999999999).'.jpg';
    $kakaka = $gosho;

    if(isset($_POST['send_photo'])) {
        if($_FILES['pictureUpload_1']['name']) {
            $extension = strtolower(end(explode('.', $_FILES['pictureUpload_1']['name'])));
            if($extension == 'jpg' || $extension == 'jpeg') {
                if(!$_FILES['pictureUpload_1']['error']) {
                //  $new_file_name = $new_name;
                    if($_FILES['pictureUpload_1']['size'] > (1024000)) {
                        $valid_file = false;
                        $error = 'Oops!  Your profile picture\'s size is to large.';
                    }
                    $valid_file = true;
                    if($valid_file) {
                        move_uploaded_file($_FILES['pictureUpload_1']['tmp_name'], 'uploads/chat/'.$gosho);
                    //  $db->query("INSERT INTO media_chat (id,user_id,path,time) VALUES ('','".$user_id."','".$new_file_name."','".time()."')");
                    }
                } else {
                    $error = 'Error occured:  '.$_FILES['pictureUpload_1']['error'];
                }
            }
        }
    }
    $picac = 'http://ift.tt/1Nu51wf'.$kakaka;
    ?>
    <form target="iframe" method="post" enctype="multipart/form-data">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel"><?php echo $lang['Emoticons']?></h4>
            </div>
            <div class="modal-body">
                <label for="pictureUpload_1">Добави снимка в чата</label>
                <input type="file" name="pictureUpload_1" data-classbutton="btn btn-default" data-classinput="form-control inline" class="form-control filestyle">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo $lang['Close']?></button>
                 <?php ?>
                <button type="submit" name="send_photo" class="btn btn-danger" onclick="appendToMessage('<?php echo $picac; ?>')"><?php echo $lang['Upload']?>       </button>
                <iframe name="iframe" id="iframe" style="display:none" ></iframe>
            </div>
        </div>
    </form>
    </div>
</div>




Aucun commentaire:

Enregistrer un commentaire