Exemple #1
0
function uploadImage2($fileID, $directory)
{
    $filename = NULL;
    if (isset($_FILES[$fileID]["type"])) {
        $validextensions = array("jpeg", "jpg", "png");
        $temporary = explode(".", $_FILES[$fileID]["name"]);
        $imagen_extension = end($temporary);
        if (($_FILES[$fileID]["type"] == "image/png" || $_FILES[$fileID]["type"] == "image/jpg" || $_FILES[$fileID]["type"] == "image/jpeg") && $_FILES[$fileID]["size"] < 10000000 && in_array($imagen_extension, $validextensions)) {
            if ($_FILES[$fileID]["error"] > 0) {
                echo "Return Code: " . $_FILES[$fileID]["error"] . "<br/><br/>";
            } else {
                //if (file_exists($directory . "/" . $_FILES[$fileID]["name"])) {
                //	echo $_FILES[$fileID]["name"] . " <span id='invalid'><b>already exists.</b></span> ";
                //}
                //else
                //{
                $filename = cleanForShortURL($_FILES[$fileID]['name']);
                $sourcePath = $_FILES[$fileID]['tmp_name'];
                // Storing source path of the imagen in a variable
                $targetPath = $directory . "/" . $filename;
                // Target path where imagen is to be stored
                // if directory doesn't exist, it is created.
                if (!file_exists($directory)) {
                    mkdir($directory, 0777, true);
                }
                move_uploaded_file($sourcePath, $targetPath);
                // Moving Uploaded imagen
                //$filename = $_FILES[$fileID]['name'];
                /*echo "<span id='success'>Image Uploaded Successfully...!!</span><br/>";
                		echo "<br/><b>File Name:</b> " . $_FILES["imagen"]["name"] . "<br>";
                		echo "<b>Type:</b> " . $_FILES["imagen"]["type"] . "<br>";
                		echo "<b>Size:</b> " . ($_FILES["imagen"]["size"] / 1024) . " kB<br>";
                		echo "<b>Temp imagen:</b> " . $_FILES["imagen"]["tmp_name"] . "<br>";*/
                //}
            }
        } else {
            echo "<span id='invalid'>***Invalid imagen Size or Type***<span>";
        }
    }
    return $filename;
}
Exemple #2
0
     exit_status('Only ' . implode(',', $allowed_ext) . ' files are allowed!');
 }
 if ($demo_mode) {
     // File uploads are ignored. We only log them.
     $line = implode('		', array(date('r'), $_SERVER['REMOTE_ADDR'], $pic['size'], $pic['name']));
     file_put_contents('log.txt', $line . PHP_EOL, FILE_APPEND);
     exit_status('Uploads are ignored in demo mode.');
 }
 // Move the uploaded file from the temporary
 // directory to the uploads folder:
 /****************************************************************/
 // if directory doesn't exist, it is created. Added by Juan Luis Almazo - May 7, 2014.
 if (!file_exists($upload_dir)) {
     mkdir($upload_dir, 0777, true);
 }
 $cleanFileName = cleanForShortURL($pic['name']);
 /****************************************************************/
 //if(move_uploaded_file($pic['tmp_name'], $upload_dir.$pic['name'])){
 if (move_uploaded_file($pic['tmp_name'], $upload_dir . $cleanFileName)) {
     // Modified by Juan Luis Almazo - May 8, 2014.
     /****************************************************************/
     // Added by Juan Luis Almazo - May 8, 2014.
     // Write images data into database.
     mysql_select_db($database, $dbConn);
     $insertSQL = sprintf("INSERT INTO imagenesCarrusel (filename, orden) SELECT %s, IFNULL((MAX(orden) + 1), 1) FROM imagenesCarrusel; /*SELECT LAST_INSERT_ID();*/", GetSQLValueString($cleanFileName, "text"));
     $result = mysql_query($insertSQL, $dbConn) or die(mysql_error());
     $query = "SELECT MAX(id_imagen) FROM imagenesCarrusel";
     $result = mysql_query($query, $dbConn) or die(mysql_error());
     $row_id = mysql_fetch_assoc($result);
     $id = $row_id['MAX(id_imagen)'];
     /****************************************************************/