Hola a todos.
Estoy haciendo un pequeño ejemplo intentado mover un archivo que he cargado con un formulario y moverlo a una carpeta.
Cuando lo ejecuto no me aparece nada.
El codigo que estoy utilizando es el siguiente:
Archivo form.php
Código:
<!DOCTYPE html>
<html>
<head>
<title>Upload Files using normal form and PHP</title>
</head>
<body>
<form enctype="multipart/form-data" method="post" action="upload.php">
<div class="row">
<label for="fileToUpload">Select a File to Upload</label><br />
<input type="file" name="fileToUpload" id="fileToUpload" />
</div>
<div class="row">
<input type="submit" value="Upload" />
</div>
</form>
</body>
</html>
Archivo upload.php
Código:
<?php
// fileToUpload is the name of our file input field
if ($_FILES['fileToUpload']['error'] > 0) {
echo "Error: " . $_FILES['fileToUpload']['error'] . "<br />";
} else {
echo "File name: " . $_FILES['fileToUpload']['name'] . "<br />";
echo "File type: " . $_FILES['fileToUpload']['type'] . "<br />";
echo "File size: " . ($_FILES['fileToUpload']['size'] / 1024) . " Kb<br />";
echo "Temp path: " . $_FILES['fileToUpload']['tmp_name']. "<br />";
$validExtensions = array('.jpg', '.jpeg', '.gif', '.png');
// get extension of the uploaded file
$fileExtension = strrchr($_FILES['fileToUpload']['name'], ".");
$fileExtension = strtolower($fileExtension);
// check if file Extension is on the list of allowed ones
if (in_array($fileExtension, $validExtensions)) {
// we are renaming the file so we can upload files with the same name
// we simply put current timestamp in fron of the file name
$newName = time() . '_' . $_FILES['fileToUpload']['name'];
echo $newName;
$destination = 'uploads/' . $newName;
if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $destination)) {
echo 'File ' .$newName. ' succesfully copied';
}
} else {
echo 'You must upload an image...';
}
}
?>
He estado mirando por internet y no se me ocurre que puede ser.
Un Saludo.