简体   繁体   中英

move_uploaded_file / No such file or directory in PHP

i have a problem with the move_uploaded_file function this is the problem:

Warning: move_uploaded_file(/imagenes/Icon.png) [function.move-uploaded-file]: failed to >open stream: No such file or directory in /home/decc98/public_html/php/insert.php on line 6

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpIBBh5U' >to '/imagenes/Icon.png' in /home/decc98/public_html/php/insert.php on line 6

Insercion exitosa

Other stuff, i speak spanish so part of my code is in spanish... Anyways, my code is:

    <?php
    include "conexion.php";
    $ruta = "/imagenes";
    $archivo = $_FILES['imagen']['tmp_name'];
    $nombreArchivo = $_FILES['imagen']['name'];
    move_uploaded_file($archivo,$ruta."/".$nombreArchivo);
    $ruta=$ruta."/".$nombreArchivo;
    $texto = $_POST['descripcion'];
    $id = rand(1,200);
    $insertar = mysql_query("INSERT INTO tablaUno VALUES('".$id."','".$ruta."','".$texto."')");
    if ($insertar) {
        echo "Inserción exitosa";
    }else{
        echo "Fallo en la inserción";
    }

    ?>

Please if anyone can help me I would appreciate it!

You need to use a relative path instead of an absolute path.

For example:

$ruta = "imagenes";

leaving out the / at the beginning of your folder name, if you're using your script from the root.

Or, something like:

$ruta = "../imagenes";

depending on the script execution's location.

Note: Using / is mostly used for an (server) absolute path, something to the affect of:

/var/user/user123/public_html/imagenes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM