Jump to content
GarryOne

[PHP Problem] Upload script

Recommended Posts

nu functioneaza codul si vreau ca voi sa-mi spuneti unde e greseala, si ce sa fac ca sa repar codul sa functioneze.

imi apare Parse error: syntax error, unexpected T_ELSE in /home/a9540258/public_html/www/upload.php on line 31.

ideea era, sa fac un script care sa accepta doar extensiile .txt .xml. .html .htm , daca fisierul uploadat nu respecta aceasta conditie sa se afeseze die($file['name'].' is an invalid file type!<br/>'); , daca uploadul se efectueaza cu succes sa-mi arata continutul fisierul uploadat.

upload.php

<?php
include('utilities.php');

$folder="data/images/";
$foto=$folder.'file.txt';

if ($_FILES['foto']['tmp_name'])
{
move_uploaded_file($_FILES['foto']['tmp_name'], "$foto");
$allowedExtensions = array("txt","htm","html","xml");

if ($file['tmp_name'] > '') {
if (!in_array(end(explode(".",
strtolower($file['name']))),
$allowedExtensions)) {
die($file['name'].' is an invalid file type!<br/>');
}
}
}

if ( $type!= "txt")
{
$_SESSION['error']='<p>Eroare. Incercati din nou.</p>';
unlink($foto);
redir('index.php');
}
else
{
redir('index.php?rs=ok');
}
else
{
redir('index.php');
}
?>

home.php


<?php
if(isset($_GET['rs']))
{
$result=$_GET['rs'];
}
if($result=='ok')
{
echo 'data/images/file.txt';
}
else
{
if(!empty($_SESSION['error']))
{
echo $_SESSION['error'];
$_SESSION['error']="";
}
echo '<form action="upload.php" method="post" enctype="multipart/form-data" name="upload" >
<input type="file" name="foto" />
<br />
<input type="submit" value="Uploadeaza" />
</form>';
}
?>

Edited by GarryOne
Link to comment
Share on other sites

ai 2 else-uri aiurea


else
{
redir('index.php?rs=ok');
}

si


else
{
redir('index.php');
}

in plus ai o "}" aiurea pusa,

incearca cu asta


<?php
include('utilities.php');

$folder="data/images/";
$foto=$folder.'file.txt';

if ($_FILES['foto']['tmp_name'])
{
move_uploaded_file($_FILES['foto']['tmp_name'], "$foto");
$allowedExtensions = array("txt","htm","html","xml");

if ($file['tmp_name'] > '')
{
if (!in_array(end(explode(".",
strtolower($file['name']))),
$allowedExtensions))
{
die($file['name'].' is an invalid file type!<br/>');
}
}
//mutam "}" de aici mai jos

if ( $type!= "txt")
{
$_SESSION['error']='<p>Eroare. Incercati din nou.</p>';
unlink($foto);
redir('index.php');
}
else
{
redir('index.php?rs=ok');
}
} // aici
else
{
redir('index.php');
}
?>

Link to comment
Share on other sites

mc, ceva ceva se misca, cand uploadez un fisier cu extensia in afara de acele propuse, imi da eroare, cum ar trebui, insa problema este ca cand uploadez un fisier text, nu se uploadeaza cu succes si nu-mi arata continutul insa imi da eroare la fel ca si cu ma as uploada alt tip de extensie.

m-am uitat in folderul respectiv unde trebuia sa se uploadeze fisierul si nu este nimic

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...