Tuesday 31 December 2019

mysql - 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:



        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!


Answer



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

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...