I create a script to upload a image and write the link-name of the image in the mysqli to use to show the image after, but the second part does not work. The script does not give any problem... but it has. The script does not write the link-name of the image what is uploading on the ftp server to use that to show on the image.
the script
<?php require '../conx.php';
session_start();
if(isset($_SESSION["userID"])){
} else{
header('Location: ../login.php');
}
?>
<?php
$ftp_server = "xxxx";
$ftp_user_name = "xxxx";
$ftp_user_pass = "xxxx";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "<font color='red'>FTP connection has failed!</font>";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected succes to $ftp_server, for user $ftp_user_name <br>";
}
//conditii pentru imagini
$max_filesize = 550428;//cati KB sa aiba maxim
//pentru multiple upload
for( $i = 0 ; $i < count( $_FILES['fileMultiple']['name'] ) ; $i++ )
{
$destination_file = "/public_html/images/stiatica/" . $_FILES['fileMultiple']['name'][$i];
$source_file = $_FILES['fileMultiple']['tmp_name'][$i];
$numePoza = $_FILES['fileMultiple']['name'];// pentru a lua numele de la imagine pentru queries
//conditie
if(filesize($_FILES['fileMultiple']['tmp_name'][$i]) > $max_filesize)
die("The file you attempted to upload ($source_file) <font color='red'>is too large</font>. MAXIM avaible to uploade $max_filesize ");
// upload the file propriu zisa~
if (ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY)) {
echo "Successfully uploaded<font color='blue'> $destination_file\n </font><br>";
//SA adauge o poza noua direct...
$numePoza = $_POST['name'];
// Filter Function -------------------------------------------------------------------
function filterFunction ($var) {
$var = nl2br(htmlspecialchars($var));
$var = str_replace("/", "\\\\", $var);
$var = preg_replace("~/~", "\\\\", $var);
return $var;
}
$numePoza = filterFunction($numePoza);
// Filter Function -------------------------------------------------------------------
// Add the info into the database table
$stmt = $con->prepare("INSERT INTO quotepoze name VALUES ?");
// TODO check that $stmt creation succeeded
// "s" means the database expects a string
$stmt->bind_param("s", $numePoza);
$stmt->execute();
$stmt->close();
echo 'Poza a fost adaugata cu succes<br /><a href="../administrator/admin_index.php">inapoi la ADMIN</a>';
//stop adaugare poza noua
} else {
echo "There was a problem while uploading $destination_file\n ";
}
}
// close the FTP stream
ftp_close($conn_id);
?>
the form
<form action="upload_image_stiatica.php" enctype="multipart/form-data" method="post">
<!--folosimg name= nume[] pentru a upload mai multe fisere, de asenebea accept=image/jpg pentru imagini -->
<input name="fileMultiple[]" type="file" accept="image/jpeg" multiple />Upload foto in folderul istorie/imagini/ pentru ARTICOL
<input name="submit" type="submit" value="Uploadeaza o noua POZA" />
</form>
The showing page is work, on the mysqli database i have black space on the name
tabel.. so there i this is the problem...