rss
Rechercher : dans
Par : Pertinence Date Nom d'utilisateur
Statut : Non résolu

Uploader image

Posté par drig, le vendredi 18 janvier 2008 à 17:33:58
Bonjour,
j'ai besoin d'aide j'ai telecharger un script d'upload d'image mais kan j'execute dans Easyphp,je reçoi un message d'erreur ke je ne sais comment le resoudre.voici le script +le message:


Notice: Undefined variable: task in c:\program files\easyphp1-8\www\upload_3864\upload.php3 on line 183

<?php

/* loading language file */
function get_translations($lngfile) {

if (file_exists($lngfile)) {
$lines = file($lngfile);
while (list(,$line) = each($lines)) {
list($key,$val)= explode("=",$line);
$phrases[$key] = $val;
}
return $phrases;
} else {
return false;
}
}
/* translate a string */
function translate($str,$vals="") {

global $phrases;

if ($phrases) {
$p_str = $phrases[$str];
if ($p_str == "") {
$p_str = $str;
}
} else {
$p_str = $str;
}

if (gettype($vals)=="array") {
$p_str = sprintf($p_str,$vals[0],$vals[1],$vals[2],$vals[3],$vals[4],­$vals[5],$vals[6]);
}

return (trim($p_str));
}

$my_max_file_size = "102400"; # in bytes
$image_max_width = "800";
$image_max_height = "800";
$the_path = "image/";

$registered_types = array(
"application/x-gzip-compressed" => ".tar.gz, .tgz",
"application/x-zip-compressed" => ".zip",
"application/x-tar" => ".tar",
"text/plain" => ".html, .php, .txt, .inc (etc)",
"image/bmp" => ".bmp, .ico",
"image/gif" => ".gif",
"image/pjpeg" => ".jpg, .jpeg",
"image/jpeg" => ".jpg, .jpeg",
"application/x-shockwave-flash" => ".swf",
"application/msword" => ".doc",
"application/vnd.ms-excel" => ".xls",
"application/octet-stream" => ".exe, .fla (etc)"
);

$allowed_types = array("image/bmp","image/gif","imag­e/pjpeg","image/jpeg");

# --

function form($error=false) {

global $PHP_SELF,$my_max_file_size,$lng;

if ($error) print $error . "<br><br>";

print "\n<form ENCTYPE=\"multipart/form-data\" action=\"upload.php3\" method=\"post\">";
print "\n<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $my_max_file_size . "\">";
print "\n<INPUT TYPE=\"hidden\" name=\"task\" value=\"upload\">";
print "\n<P>".translate("Upload images")."";
print "\n<BR>NOTE: ".translate("Max file size is")." " . ($my_max_file_size / 1024) . "KB";
print "\n<br><INPUT NAME=\"the_file\" TYPE=\"file\" SIZE=\"35\"><br>";
print "\n<input type=\"submit\" Value=\"Upload\">";
print "\n</form>";

} # END form

# --

if (!ereg("^4",phpversion())) {
function in_array($needle,$haystack) { # we have this function in PHP4, so for you PHP3 people
for ($i=0; $i < count($haystack); $i++) {
if ($haystack[$i] == $needle) {
return true;
}
}
}
}

# --

function validate_upload($the_file) {

global $my_max_file_size, $image_max_width, $image_max_height,$allowed_types,$the_file_type,$registered_­types;

$start_error = "\n<b>Error:</b>\n<ul>";

if ($the_file == "none") { # do we even have a file?

$error .= "\n<li>You did not upload anything!</li>";

} else { # check if we are allowed to upload this file_type

if (!in_array($the_file_type,$allowed_types)) {
$error .= "\n<li>The file that you uploaded was of a type that is not allowed, you are only
allowed to upload files of the type:\n<ul>";
while ($type = current($allowed_types)) {
$error .= "\n<li>" . $registered_types[$type] . " (" . $type . ")</li>";
next($allowed_types);
}
$error .= "\n</ul>";
}

if (ereg("image",$the_file_type) && (in_array($the_file_type,$allowed_types))) {

$size = GetImageSize($the_file);
list($foo,$width,$bar,$height) = explode("\"",$size[3]);

if ($width > $image_max_width) {
$error .= "\n<li>Your image should be no wider than " . $image_max_width . " Pixels</li>";
}

if ($height > $image_max_height) {
$error .= "\n<li>Your image should be no higher than " . $image_max_height . " Pixels</li>";
}

}

if ($error) {
$error = $start_error . $error . "\n</ul>";
return $error;
} else {
return false;
}
}
} # END validate_upload

# --


function list_files() {

global $the_path;

$handle = dir($the_path);
print "\n<b>Uploaded files:</b><br>";
while ($file = $handle->read()) {
if (($file != ".") && ($file != "..")) {
print "\n" . $file . "<br>";
}
}
print "<hr>";
}

# --

function upload($the_file) {

global $the_path,$the_file_name;

$error = validate_upload($the_file);
if ($error) {
form($error);
} else { # cool, we can continue
if (!@copy($the_file, $the_path . "/" . $the_file_name)) {
form("\n<b>Something barfed, check the path to and the permissions for the upload directory</b>");
} else {
list_files();
form();
}
}
} # END upload

# --

############ Start page

print "<html>\n<head>\n<title>Upload example</title>\n</head>\n<body>";
echo("<table width=\"0%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
<tr align=\"left\">
<td><font face=verdana size=2>");
switch($task) {
case 'upload':
upload($the_file);
break;
default:
form();
}
echo("</font></td>
</tr>
</table>");
print "\n</body>\n</html>";

?>
Configuration: Windows XP
Firefox 2.0.0.11
Répondre à drig  Signaler ce message aux modérateurs Aller au dernier message

1


  • Ce message vous semble utile, votez !
  • Signaler ce message aux modérateurs
bibi675, le vendredi 18 janvier 2008 à 19:29:28
Salut,
Le SMS est interdit ici, de plus, sais-tu au moins comment fonctionne ce script ? Pour faire un upload moi j'utilise 10-15 lignes (en comptant les vérifications) et toi tu en utilise le triple ! Cherche un peu sur internet tu trouvera des formulaires d'upload beaucoup plus simple.

@++
Répondre à bibi675

2


  • Ce message vous semble utile, votez !
  • Signaler ce message aux modérateurs
 hervens, le lundi 31 mars 2008 à 05:24:44
Si tu essayes d'ajouter un outil pour uploader des images dans ton site, utilise le mien!

Va sur http://www.thefilegarage.com/siteUpload.aspx et suis les instructions.

Si quelque chose ne marche pas, fais le moi savoir.
C'est a moi le site.

Je peux aussi te passer mon script, qui te permet d'uploader une image dans une base de donner mysql, et de les remontrer par la suite dans le browser si tu veux.
Répondre à hervens
Logiciels pertinents trouvés dans les téléchargements
Télécharger Image Resizer 1Image Resizer - Petit utilitaire (PowerToy) basique, très simple, permettant de réduire la taille d'une image, dans le but, notamment, de...Catégorie: Graphisme
Licence: Freeware/gratuit
Télécharger VSO Image Resizer 2.0.1.9VSO Image Resizer - Le logiciel VSO Image Resizer organise vos photos en réduisant leur résolution et en les déplaçant facilement au sein de...Catégorie: Graphisme
Licence: Freeware/gratuit
Télécharger ImageWell 3.5.3ImageWell - ImageWell n'est pas à proprement parler un logiciel de Retouche photo. Il permet plutôt de préparer des images pour le...Catégorie: Retouche photo
Licence: Freeware/gratuit
Télécharger ImagePlay  0.3ImagePlay - Si vous n'êtes pas un pro dans la manipulation des brushes et autres outils de retouche d'images, adoptez ImagePlay et voyez...Catégorie: Retouche photo
Licence: Open Source
Plus de logiciels gratuits sur « uploader image »