tags:

views:

106

answers:

7

The code looks like this:

html

<form action="contact.php" method="post" enctype="multipart/form-data" onsubmit="return Validare();">

    <input type="text" name="nume" value="Nume" class="contact" id="Nume" onclick="if(this.value=='Nume')this.value='';" onblur="if(this.value.replace(/^\s+|\s+$/g,'')=='')this.value='Nume'" /><font color="red">*</font><br />
   <input type="text" name="email" value="Email" class="contact" id="Email" onclick="if(this.value=='Email')this.value='';" onblur="if(this.value.replace(/^\s+|\s+$/g,'')=='')this.value='Email'" /><font color="red">*</font><br />
   <input type="text" name="telefon" value="Telefon" class="contact" id="Telefon" onclick="if(this.value=='Telefon')this.value='';" onblur="if(this.value.replace(/^\s+|\s+$/g,'')=='')this.value='Telefon'" /><br />
   <textarea name="mesaj" rows="10" class="contact" id="Mesaj" onclick="if(this.value=='Mesaj')this.value='';" onblur="if(this.value.replace(/^\s+|\s+$/g,'')=='')this.value='Mesaj'">Mesaj</textarea>

<input type="file" name="file[]" />
<input type="file" name="file[]" />
<input type="file" name="file[]" />
<input type="submit" value="Trimite" />
</form>

php

for($i=0; $i<3; $i++){
if($_FILES["file"]["size"][$i] > 0){
 $rand = rand(10000, 99999);
 $name = $rand.rand(10000, 99999).$_FILES["file"]["name"][$i];
            $tmp_name = $_FILES["file"]["tmp_name"][$i];
 $target_path_big = "http://biroutraduceri.net/fisiere/".$name;
 move_uploaded_file($tmp_name, "fisiere/".$name);
}
}

javascript

<script>
function Validare(){
 if(document.getElementById("Nume").value.replace(/^\s+|\s+$/g,'') == "" || document.getElementById("Nume").value.replace(/^\s+|\s+$/g,'') == "Nume"){
  alert("Numele nu este valid!");
  return false;
 }
 if(document.getElementById("Email").value.replace(/^\s+|\s+$/g,'') == "" || document.getElementById("Email").value.replace(/^\s+|\s+$/g,'') == "Email"){
  alert("Email-ul nu este valid!");
  return false;
 }
 if(document.getElementById("Mesaj").value.replace(/^\s+|\s+$/g,'') == "" || document.getElementById("Mesaj").value.replace(/^\s+|\s+$/g,'') == "Mesaj"){
  alert("Mesajul nu este valid!");
  return false;
 }
 return true;
}
</script>

When I press submit nothing happen. The file isn't uploaded.

Where I'm wrong???

A: 

i guess onsubmit="return Validare();" is returning false

why are you using this rand function anyway, try time() it's better i think

antpaw
Do not use time(). He is using the rand() function to try and get a pseudo random number. If you use time(), you will not get this as multiple files can be uploaded in a given second.
Brad
A: 

you want $_FILES['file'][$i]['size']

contagious
Sorry, but that's wrong: http://www.php.net/manual/en/features.file-upload.multiple.php
R. Bemrose
+1  A: 

$tmp_name is never initialized to anything.

$tmp_name should be set equal to $_FILES['file']['tmp_name'][$i];

Brad
2. is incorrect: http://www.php.net/manual/en/features.file-upload.multiple.php
Lucas Oman
@Lucas Which part are you referring to?
Peter Lindqvist
It was a comment that I had removed.
Brad
Confusing.. :) My bad.
Peter Lindqvist
@Peter Lindqvist: Yes, it's one of my biggest complaints with the "not marked as edited if done within 5 minutes" thing.
R. Bemrose
A: 

You realy dont need the onsubmit="return Validare();" and it is even written wrong. and move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) is the correct code for

streetparade
You still need the index at the end of $_FILES['file']['tmp_name'] so that the correct file is referenced.
Brad
I need this onsubmit="return Validare();" for validation.
Emanuel
this is true and valid in most cases, i agree :)
streetparade
A: 

You forgot to set up the variable $tmp_name. As in $tmp_name = $_FILES["file"]["tmp_name"][$i]; Otherwise, it seems ok as per my own tests.

Otherwise, throw in a print_r($_FILES); before your "for" loop, a couple more prints and a is_readable($tmp_name) check inside your loop, just to more finely try to pin-point the source of the problem.

DrYak
in echo is_readable($tmp_name); it show 1.
Emanuel
+2  A: 

Your PHP code has an error, the $tmp_name is never set.

Corrected code

for($i=0; $i<3; $i++){
    if($_FILES["file"]["size"][$i] > 0){
        $rand = rand(10000, 99999);
        $name = $rand.rand(10000, 99999).$_FILES["file"]["name"][$i];
        $target_path_big = "http://biroutraduceri.net/fisiere/".$name;
        move_uploaded_file($_FILES["file"]["tmp_name"][$i], "fisiere/".$name);
    }
}
Peter Lindqvist
The problem is not there.
Emanuel
And is the target directory "is_writeable" ? Together with all the necessary unix file permission ? For example, the directory could be chmoded to 0775 "rwxrwxr-x" with a group set to "www" or "apache" (or whatever the PHP process is running as).
DrYak
A: 

Could be a permission problem, does your script have permission to write in "fisiere/".$name and is "fisiere/".$name really where you think it is? You might want to use an absolute path.

Edit: You cannot write an image to a http url, you need to write it to a local file-path and you need to make sure php has permissions to write to that path / directory

jeroen
I've try even with "http : // url / fisiere /"; . $name, but nothing.
Emanuel