Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

sending file with curl #27

Open
eventhorizonpl opened this issue Apr 19, 2014 · 0 comments
Open

sending file with curl #27

eventhorizonpl opened this issue Apr 19, 2014 · 0 comments

Comments

@eventhorizonpl
Copy link

Hi,

I'm trying to send a file with curl, but I'm getting an exception. Here is a php code - it works well with php cli interpreter

$data = array(
'file' => '@'.realpath($reportValue['file']),
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$head = curl_exec($ch); <-- this throws an error
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

Here is an exception that I get:

(translation)
Unhandled exception: PHP.Core.PhpNetInternalException: Guarded call InnerException: The process can not access the file 'C: \ Users \ Michal \ AppData \ Local \ Temp \ testfile.txt "because it is being used by another process.

Is there any way to get working file sending over curl?

Best regards,
Michal

Wyjątek nieobsłużony: PHP.Core.PhpNetInternalException: Guarded call InnerException: Proces nie może uzyskać dostępu do pliku "C:\Users\Michal\AppData\Local\Temp\testfile.txt", ponieważ jest on używany przez inny proces.
at w System.IO._Error.WinIOError(Int32 errorCode, String maybeFullPath)
w System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
w System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
w System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
w PHP.Library.Curl.HttpFormDataUploader.UploadForm(CurlForm form)
w PHP.Library.Curl.CurlHttp.Execute(PhpCurlResource curl, CURLcode& result)
w PHP.Library.Curl.Curl.Execute(PhpResource ch)
w PHP.Core.ScriptContext.CallInternal(Dictionary2 localVariables, NamingContext namingContext, Object name, String fallbackName, DRoutineDesc& routineHint,ScriptContext context) w PHP.Core.ScriptContext.CallValue(Dictionary2 localVariables, NamingContextnamingContext, Object name, String fallbackName, DRoutineDesc& routineHint, ScriptContext context)
w <ww.php>.WorkWatcherClient.sendReports(ScriptContext ) w P:\misc\client\ww.php:wiersz 90
w <ww.php>.WorkWatcherClient.process(ScriptContext ) w P:\misc\client\ww.php:wiersz 44
w <ww.php>.WorkWatcherClient.start(ScriptContext ) w P:\misc\client\ww.php:wiersz 125
w start
(WorkWatcherClient , ScriptContext )
w System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid3[T0,T1,T2](CallSite site, T0 arg0, T1 arg1, T2 arg2)
w <ww.php>.<Script>.

(ScriptContext , Dictionary2 <locals>, DObject <self>, DTypeDesc <includer>, Boolean <request>) w P:\misc\client\ww.php:wiersz 133 w PHP.Core.ScriptContext.GuardedMain(Object mainRoutine) w PHP.Core.ScriptContext.GuardedCall[TData,TResult](Converter2 routine, TData data, Boolean allowUserExceptions)
---> System.IO.IOException: Proces nie może uzyskać dostępu do pliku "C:\Users\Michal\AppData\Local\Temp\testfile.txt", ponieważ jest on używany przez inny proces.
w System.IO._Error.WinIOError(Int32 errorCode, String maybeFullPath)
w System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
w System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
w System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
w PHP.Library.Curl.HttpFormDataUploader.UploadForm(CurlForm form)
w PHP.Library.Curl.CurlHttp.Execute(PhpCurlResource curl, CURLcode& result)
w PHP.Library.Curl.Curl.Execute(PhpResource ch)
w PHP.Core.ScriptContext.CallInternal(Dictionary2 localVariables, NamingContext namingContext, Object name, String fallbackName, DRoutineDesc& routineHint, ScriptContext context) w PHP.Core.ScriptContext.CallValue(Dictionary2 localVariables, NamingContext namingContext, Object name, String fallbackName, DRoutineDesc& routineHint, ScriptContext context)
w <ww.php>.WorkWatcherClient.sendReports(ScriptContext ) w P:\misc\client\ww.php:wiersz 90
w <ww.php>.WorkWatcherClient.process(ScriptContext ) w P:\misc\client\ww.php:wiersz 44
w <ww.php>.WorkWatcherClient.start(ScriptContext ) w P:\misc\client\ww.php:wiersz 125
w start
(WorkWatcherClient , ScriptContext )
w System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid3[T0,T1,T2](CallSite site, T0 arg0, T1 arg1, T2 arg2)
w <ww.php>.<Script>.(ScriptContext , Dictionary2 <locals>, DObject <self>, DTypeDesc <includer>, Boolean <request>) w P:\misc\client\ww.php:wiersz 133 w PHP.Core.ScriptContext.GuardedMain(Object mainRoutine) w PHP.Core.ScriptContext.GuardedCall[TData,TResult](Converter2 routine, TData data, Boolean allowUserExceptions)
--- Koniec śladu stosu wyjątków wewnętrznych ---
w PHP.Core.ScriptContext.GuardedCall[TData,TResult](Converter`2 routine, TData data, Boolean allowUserExceptions)
w PHP.Core.ScriptContext.RunApplication(Delegate mainRoutine, String relativeSourcePath, String sourceRoot)
w .Run(String[] )

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant