Jump to content

LucaCrippa

Members
  • Posts

    20
  • Joined

  • Last visited

Posts posted by LucaCrippa

  1. Hi, please could you tell me where I'm doing wrong?

     

     

    Page php 1: list of directories where to upload images (galleryedit.php)

    <?php $path = '../public/gallery';$dirs = scandir($path);foreach ($dirs as $valore) {	if($valore === '.' || $valore === '..') { continue; } 	echo "<a href=uploadimage.php?cartella=$valore> <img src="images/icons/edit.png" title="Carica" width="15" height="15"> </a>     $valore </br>";}?>

    Page php 2: form to upload image, which takes the name of the folder where I want to upload (uploadimage.php)

    <?php$path = '../public/gallery';$cartella = $path .'/'. $_GET['cartella'];echo "<form action="upload.php?updir=$cartella" method="post" enctype="multipart/form-data">    <input name="image" type="file" size="40" />    <br /><br />    <input name="submit" type="submit" value="Carica immagine" /></form>";?>

    Page php 3: the uploading facility, which takes the name of the folder (upload.php)

    <?php $path = '../public/gallery';$dir = $_GET['updir'];if(!isset($_SERVER['DOCUMENT_ROOT'])){ if(isset($_SERVER['SCRIPT_FILENAME'])){	$_SERVER['DOCUMENT_ROOT'] = str_replace( '', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF']))); };}; if(!isset($_SERVER['DOCUMENT_ROOT'])){ if(isset($_SERVER['PATH_TRANSLATED'])){	$_SERVER['DOCUMENT_ROOT'] = str_replace( '', '/', substr(str_replace('', '', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF']))); };};$PercorsoDominio = $_SERVER['DOCUMENT_ROOT'];$public = "/$path/$dir/";if(is_dir($PercorsoDominio.$public)){ continue; }else{ exit; }if ((($_FILES["file"]["type"] == "image/gif") ||($_FILES["file"]["type"] == "image/jpeg") ||($_FILES["file"]["type"] == "image/pjpeg") && ($_FILES["file"]["size"] < 20000000)) )  {  if ($_FILES["file"]["error"] > 0)    {    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";    }  else    {		   if (file_exists($PercorsoDominio. $public . $_FILES["file"]["name"]))      { continue; }    else      {      move_uploaded_file($_FILES["file"]["tmp_name"],	       $PercorsoDominio. $public . $_FILES["file"]["name"]);    include("uploadsuccess.php");	        }    }  }else  {    include("uploaderror.php");  }}?>

    Thank you!!

  2. you can always search for it. top result gives a pretty straightforward answer

    https://www.google.com/search?q=tell+if+form+was+submitted&oq=tell+if+form+was+submitted&aqs=chrome..69i57j69i60l5.6173j0j7&sourceid=chrome&espvd=210&es_sm=119&ie=UTF-8#es_sm=119&q=tell+if+form+was+submitted+php&safe=off

     

    while I understand it can be frustrating, we're hear to teach first. We're more inclined to give assistance after you have attempted the task first. We don't generally just give out the answer, and instead initially defer to guidance and suggestion.

    Sure, but if I ask for info directly in a forum I would like to have an answer, just because there are many guides on the web... if one cannot solve its problems with guides, he asks in forums...

     

    Anyway, I'm trying Ingolme solution ;)

  3. You haven't checked that the form was submitted. You're telling it to redirect every time. Aside from that, you're sending the header after having used an echo statement.

    You are not telling me the solution. I know that I need to redirect only if the submit button is pressed, but I don't know how to do it.

    header('Location: ./Index.php');bla bla blaecho "<h7>Modifica l'evento</h7><p><form action="$_SERVER[php_self]" method= "post" ><textarea name="newd" cols="100%" rows="18"> $data </textarea><input type="submit" value="Salva modifiche" name="submitted"></form>";if($_SERVER['REQUEST_METHOD'] == "POST") {	exit;}

    Not working. Found here: http://electrokami.com/coding/the-correct-way-to-check-php-form-submission/ last paragraph.

  4. Well, that depends on where you call the header() function from. You should tell PHP to only call the header() function after the form is submitted.

    <?php			// set file to read$path = '../public/events';$edit = $path .'/'. $_GET['edi'];  $newdata = $_POST['newd'];if ($newdata != '') {	$fw = fopen($edit, 'w') or die('Could not open file!');	$fb = fwrite($fw,stripslashes($newdata)) or die('Could not write to file');	fclose($fw);}  	$fh = fopen($edit, "r") or die("Could not open file!");  	$data = fread($fh, filesize($edit)) or die("Could not read file!");  	fclose($fh);echo "<h7>Modifica l'evento</h7><p><form action="$_SERVER[php_self]" method= "post" ><textarea name="newd" cols="100%" rows="18"> $data </textarea><input type="submit" value="Salva modifiche" ></form>";header('Location: ./Index.php');exit;?>

    Not working.

  5. In PHP the way to redirect is using a location header:

    header('Location: http://website.com/page.html');

    The header() function must be called before any HTML, text or echo statements. Despite this warning, if you do happen to come across an error that says "Headers already sent" see how to solve it here: http://w3schools.invisionzone.com/index.php?showtopic=44106

    Not working. This is redirecting to my new page as entering my php page, but I would like to redirect after clicking the button of the form.

  6. "No such file or directory" means that the file doesn't exist. The error message even told you what file you told it to open: ../public/events//

     

    That means that "$path/$edit" evaluates to "../public/events//"

    It's up to you to make sure that the path and filename are correct.

    $path = '../public/events';$edit = $path .'/'. $_GET['edi'];  $newdata = $_POST['newd'];if ($newdata != '') {	$fw = fopen($edit, 'w') or die('Could not open file!');	$fb = fwrite($fw,stripslashes($newdata)) or die('Could not write to file');	fclose($fw);}  	$fh = fopen($edit, "r") or die("Could not open file!");  	$data = fread($fh, filesize($edit)) or die("Could not read file!");  	fclose($fh);echo "<h7>Modifica l'evento</h7><p><form action="$_SERVER[php_self]" method= "post" ><textarea name="newd" cols="100%" rows="18"> $data </textarea><input type="submit" value="Salva modifiche" ></form>";

    Yeah, I managed to solve it. With this code is working, but now the problem is that when I click on button txt file is saved, but the textarea remains freezed. How can I redirect on another page, such as a edit-confirmed page?

    Thank you!

  7. The errors told you exactly what the problem is. Read them.

    Pheraps I fail to open stream, or I have no file or directory.. Or the supplied argument is not a valid stream resource, I don't know.. Or there are two /?

  8. Like Ingolme said, the first step is to get the error message. So stop suppressing error messages. You also might want to use an absolute path to the file you're trying to open.

    First, I succeeded to make secure session to protect my pages.

    Secondly, removing the @ in the editevent page brings me these errors:

     

    Warning: fopen(../public/events//) [function.fopen]: failed to open stream: No such file or directory inD:Inetpubwebscoroconcorezzoitcircolinoeditevent.php on line 42Warning: fopen(../public/events//) [function.fopen]: failed to open stream: No such file or directory inD:Inetpubwebscoroconcorezzoitcircolinoeditevent.php on line 49Warning: fread(): supplied argument is not a valid stream resource in D:Inetpubwebscoroconcorezzoitcircolinoeditevent.php on line 50Warning: fclose(): supplied argument is not a valid stream resource in D:Inetpubwebscoroconcorezzoitcircolinoeditevent.php on line52

  9. If you really want to know why it's not working, remove the @ (error suppressing) operator from @fopen();

     

    That will show you why the program isn't working.

     

    I just should warn you that if this is your page, it's really insecure. Anybody who opens the page in your browser can edit and delete any file on your server.

    Ok, I'm trying.

    No, the editing page is protected by a login page!

  10. 2.txt in this case is really located in ../public/events

    so how can I modify my code to make it working?

     

     

    edit: aaahhhh I missed a /

    I'm trying ;)

     

     

    edit2: no, it's not working at all.. :P

    Ok, the error for the delete was:

     

    $deleted = $path .'/'. $_GET['delete'];

     

    I'm stupid.

     

    I tried to fix the other problem (the edit) with the same code but I failed!

  11. for the delete, you have this page "$path = '../public/events';" but the script can ot find it since 2.txt isnt located properly so you might want your path to be $path = '../public/events/';

    2.txt in this case is really located in ../public/events

    so how can I modify my code to make it working?

     

     

    edit: aaahhhh I missed a /

    I'm trying ;)

     

     

    edit2: no, it's not working at all.. :P

  12.  

    In your edit page, the reason the error is showing up is that fopen() failed. Check that $loadcontent has the value you expected.

    You can use PHP's file_exists() function to check if the file is there before operating with it.

     

    The following code is probably failing because you did not actually use the $path value

    $path = '../public/events';$deleted = $_GET['delete'];if (!unlink($deleted)){ 

     

    $loadcontent has actually the right value, in fact when I press the edit button the content of my txt file appears! When I click on Save on the form I have that error.

     

    About the deleting code, I tried to comment the $path variable but I got the same result. It's a mess!! :D

  13. Hi there,

    I have two problems with php, in particular about variable passing.

     

    In the admin page of a website I created a form to public "news entries". The event is saved in a txt file:

     

    filename.txt contains:

     

    $title | $date | $text | $location | $time

    $path = '../public/events';	$file = fopen("../public/events/$filename","w");		echo fwrite ($file, " $title | $date | $text | $location | $time ");

    Ok, this is working. But now I would like to delete and edit text files!

     

    I tried such a thing:

     

    1) press it to delete event:

    <a href=delconfirm.php?del=$valori>Delete event</A>

    2) delconfirm.php

    <?php $path = '../public/events';$d = $_GET['del'];  echo "    <center></br></br></br></br></br></br>	Confirm? <p>    <p>	<h5><a href=delete.php?delete=$d> Yes </a><br></h5>	<p>	<p>	<h5><a href=Index.php> No </a><br></h5>	</center>	"; ?>

    3) delete.php

    <?php$path = '../public/events';$deleted = $_GET['delete'];if (!unlink($deleted)){ 	echo ("Erasing of $deleted failed<br>");     } else {     echo ("      	<CENTER></br></br></br></br></br></br>		Event $deleted succesfully erased! <p>    	<p>		<h5><a href="Index.php">Home Page</a></h5>		</CENTER>			");      }    ?>

    But I have this error:

     

    Warning: unlink(2.txt) [function.unlink]: No such file or directory in D:Inetpubwebscoroconcorezzoitcircolinodelete.php on line 19Impossibile eliminare 2.txt

     

     

    Second, the editing of a text file:

    <a href=editevent.php?edi=$valori>Edit event</A>

    1) editevent.php

    <?php$path = '../public/events';$edit = $_GET['edi'];$loadcontent = "$path/$edit";    if($save_file) {        $savecontent = stripslashes($savecontent);        $fp = @fopen($loadcontent, "w");        if ($fp) {            fwrite($fp, $savecontent);            fclose($fp);        }    }    $fp = @fopen($loadcontent, "r");        $loadcontent = fread($fp, filesize($loadcontent));        $loadcontent = htmlspecialchars($loadcontent);        	fclose($fp);?><table width="100%" border="0" vertical-align="text-top">  <tr>  <td><h7>Edit</h7><p><form method=post action="<?=$_SERVER['PHP_SELF']?>"><textarea name="savecontent" cols="55" rows="18"><?=$loadcontent?></textarea><br><input type="submit" name="save_file" value="Save!"> </form></td>

    Actually it allows me to have the txt file content in the textarea, but there are these errors:

     

    Warning: fread(): supplied argument is not a valid stream resource in D:Inetpubwebscoroconcorezzoitcircolinoeditevent.php on line 51Warning: fclose(): supplied argument is not a valid stream resource in D:Inetpubwebscoroconcorezzoitcircolinoeditevent.php on line53

     

     

     

     

     

    How can I manage it?? Thank you!!

  14. Hi there,

    I have a problem with post/get method in php forms. Here it is a form that allows the user to insert a new "blog post", including a title, a date and the text of the post.

     

     

    <form action="sendmail.php" method="post">
    <table align="left" width="80%">
    <tr>
    <td align=right><font face="Verdana,Arial" size="1"><B>Titolo</td>
    <td><font face="Verdana,Arial" size="1"><input name="title" size=28 value=""></td>
    </tr>
    <tr>
    <td align=right><font face="Verdana,Arial" size="1"><B>Data</td>
    <td><font face="Verdana,Arial" size="1"><input name="date" size=28 value=""></td>
    </tr>
    <tr>
    <td colspan=2><font face="Verdana,Arial" size="1"><B>Testo<BR><textarea name="text" cols=51 rows=10 wrap=soft></textarea></td>
    </tr>
    <tr>
    <td></td>
    <td><font face="Verdana,Arial" size="1"><input type="submit" value="Pubblica"></td>
    </tr>
    </table>
    </form>
    Now, I echo these info in a txt file:
    $file = fopen("../public/events/$filename","w");
    echo fwrite($file,"<h6> $title </h6> </br> <h5> $date </h5> <p> $text <p> </br>");
    fclose($file);
    in order to put it on my webpage.
    Now, I would like to modify a post! Also delete it, if necessary! But how can I read the txt file, extract the strings $title, $date, $text, put them into the form above and save it?
    Thank you! :)

     

  15. absolute pathC:/user/some/file/path/in/windows/user/some/file/path/in linux or relative path calling from user directoryfile/pathwill get you C:/user/some/file/pathetc
    Ok... but, what is my server path? How can I find it? D:\Inetpub\webs\coroconcorezzoit\upload4.php ?
  16. Hi there, I'm a novice on php programmin', and I just have a question 'bout a script for uploadin' pdf files on my website. I would like to allow administrator to upload pdf files in the restricted area of the site, then I would like to implement a script that generates automatically the links for the download of the uploaded pdf files. This is the code: The form for the upload:

    <form action="upload3.php" method="post" enctype="multipart/form-data">	    <input type="file" name="filepdf" /><br />	    <input type="submit" value="Upload menu pdf" name="upload_pdf" /></form>

    The upload3.php file included in the form:

    <?php    $pdfPath = "http://www.coroconcorezzo.it/Spartiti/";    $maxSize = 102400000000;    if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['upload_pdf'])) {   	    if (is_uploaded_file($_FILES['filepdf']['tmp_name'])) {		    if ($_FILES['filepdf']['type'] != "application/pdf") {			    echo '<p>Il file non è un PDF</p>';		    } else if ($_FILES['filepdf']['size'] > $maxSize) {			    echo '<p class="error">File troppo grande. Dimensione massima: ' . $maxSize . 'KB</p>';		    } else {			    $menuName = 'file.pdf';			    $result = move_uploaded_file($_FILES['filepdf']['tmp_name'], $pdfPath . $menuName);			    if ($result == 1) {				    echo '<p class="error">Menu caricato</p>';			    } else {				    echo '<p class="error">Si è verficato un errore</p>';			    }		    }	    }    }?>

    But when I try to upload a pdf file I receive this error message:

    Warning: move_uploaded_file(http://www.coroconcorezzo.it/Spartiti/file.pdf) [function.move-uploaded-file]: failed to open stream: HTTP wrapper does not support writeable connections inD:\Inetpub\webs\coroconcorezzoit\upload3.php on line 14Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\PHP\upload\phpF162.tmp' to 'http://www.coroconcorezzo.it/Spartiti/file.pdf' in D:\Inetpub\webs\coroconcorezzoit\upload3.php on line14Si è verficato un errore
    The website is www.coroconcorezzo.itHow can I fix it? Thank you! ps: the files attribution is 777 for every file and folder in my website.
×
×
  • Create New...